From be69cea228f4674862b8c25f11f044f82dbc13bb Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 10 May 2023 18:13:30 +0200 Subject: Replace XML token logging completely Using io.TeeReader and io.MultiWriter is a better debugging interface since it is exactly what is transmitted via the TCP connection. --- xmpp.go | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/xmpp.go b/xmpp.go index c9ae054..6f24c86 100644 --- a/xmpp.go +++ b/xmpp.go @@ -7,7 +7,6 @@ import ( "crypto/x509" "encoding/xml" "log" - "reflect" ) type XmppEvent uint8 @@ -35,7 +34,8 @@ func (l *Limox) xmpp(jid string, pwd string) { return } - enc := xml.NewEncoder(conn) + multiw := io.MultiWriter(conn, os.Stdout) + enc := xml.NewEncoder(multiw) receiver := make(chan xml.Token) termination := make(chan bool) @@ -88,23 +88,6 @@ func (l *Limox) xmpp(jid string, pwd string) { l.XmppEvents <- XmppDisconnect } -func logToken(t xml.Token, isTx bool) { - return - var prefix string - if isTx { - prefix = "C" - } else { - prefix = "S" - } - - switch t.(type) { - case xml.CharData: - log.Printf("%s: [ %v ] %s\n", prefix, reflect.TypeOf(t), t) - default: - log.Printf("%s: [ %v ] %+v\n", prefix, reflect.TypeOf(t), t) - } -} - func sendStreamStart(enc *xml.Encoder, jid string) (xml.EndElement) { start := xml.StartElement{ xml.Name{"jabber:client", "stream:stream"}, @@ -127,7 +110,6 @@ func sendStreamStart(enc *xml.Encoder, jid string) (xml.EndElement) { log.Fatal("Could not flush XML encoder!") } - logToken(start, true) return start.End() } @@ -141,8 +123,6 @@ func sendStreamEnd(enc *xml.Encoder, end xml.EndElement) { if err != nil { log.Fatal("Could not flush XML encoder!") } - - logToken(end, true) } // domainpart extracts the domain name from a JID / XMPP address. See -- cgit v1.2.3-70-g09d2