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", Name: "port",
Description: "Port", Description: "Port",
IsNumeric: true, IsNumeric: true,
Default: "6667", Default: "5222",
}, },
&ConfigEntry{ &ConfigEntry{
Name: "ssl", Name: "ssl",

View file

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