diff options
author | xengineering <me@xengineering.eu> | 2023-05-10 18:13:30 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-05-10 18:22:31 +0200 |
commit | be69cea228f4674862b8c25f11f044f82dbc13bb (patch) | |
tree | 7fc22cd14621f64b1eba7d08652c1961d31d6d66 | |
parent | f82aa566910de95288311076d15ebc9c4b0d279a (diff) | |
download | limox-be69cea228f4674862b8c25f11f044f82dbc13bb.tar limox-be69cea228f4674862b8c25f11f044f82dbc13bb.tar.zst limox-be69cea228f4674862b8c25f11f044f82dbc13bb.zip |
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.
-rw-r--r-- | xmpp.go | 24 |
1 files changed, 2 insertions, 22 deletions
@@ -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 |