XMPP logging

This commit is contained in:
Alex 2020-02-27 11:13:15 +01:00
parent be9278ab02
commit 11963aaf3d
2 changed files with 10 additions and 11 deletions

View file

@ -26,7 +26,7 @@ func init() {
Name: "port",
Description: "Port",
IsNumeric: true,
Default: "6667",
Default: "5222",
},
&ConfigEntry{
Name: "ssl",

View file

@ -1,11 +1,10 @@
package xmpp
import (
"time"
//"os"
"crypto/tls"
"fmt"
"strings"
"time"
gxmpp "github.com/matterbridge/go-xmpp"
"github.com/rs/xid"
@ -123,8 +122,8 @@ func (xm *XMPP) connectLoop(num int) {
xm.conn, err = options.NewClient()
if err != nil {
xm.connected = false
fmt.Printf("XMPP failed to connect / disconnected: %s\n", err)
fmt.Printf("Retrying in %ds\n", xm.timeout)
log.Debugf("XMPP failed to connect / disconnected: %s\n", err)
log.Debugf("Retrying in %ds\n", xm.timeout)
time.Sleep(time.Duration(xm.timeout) * time.Second)
xm.timeout *= 2
if xm.timeout > 600 {
@ -136,8 +135,8 @@ func (xm *XMPP) connectLoop(num int) {
err = xm.handleXMPP()
if err != nil {
xm.connected = false
fmt.Printf("XMPP disconnected: %s\n", err)
fmt.Printf("Reconnecting.\n")
log.Debugf("XMPP disconnected: %s\n", err)
log.Debugf("Reconnecting.\n")
}
}
}
@ -152,7 +151,7 @@ func (xm *XMPP) xmppKeepAlive() chan bool {
select {
case <-ticker.C:
if err := xm.conn.PingC2S("", ""); err != nil {
log.Printf("PING failed %#v\n", err)
log.Debugf("PING failed %#v\n", err)
}
case <-done:
return
@ -172,7 +171,7 @@ func (xm *XMPP) handleXMPP() error {
return err
}
fmt.Printf("XMPP: %#v\n", m)
log.Tracef("XMPP: %#v\n", m)
switch v := m.(type) {
case gxmpp.Chat:
@ -288,7 +287,7 @@ func (xm *XMPP) SetRoomInfo(roomId RoomID, info *RoomInfo) error {
func (xm *XMPP) Join(roomId RoomID) error {
xm.isMUC[string(roomId)] = true
fmt.Printf("Join %s with nick %s\n", roomId, xm.nickname)
log.Tracef("Join %s with nick %s\n", roomId, xm.nickname)
_, err := xm.conn.JoinMUCNoHistory(string(roomId), xm.nickname)
return err
}
@ -321,7 +320,7 @@ func (xm *XMPP) Send(event *Event) error {
}
}
fmt.Printf("xm *XMPP Send %#v\n", event)
log.Tracef("xm *XMPP Send %#v\n", event)
if len(event.Recipient) > 0 {
_, err := xm.conn.Send(gxmpp.Chat{
Type: "chat",