diff options
author | xengineering <me@xengineering.eu> | 2023-07-01 20:05:56 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2023-07-01 20:05:56 +0200 |
commit | ad882d60b7dabeb4d4ece6435c2fad9f23ab821f (patch) | |
tree | c53e483e72adbaa085f2383c2992e25c00ceae19 | |
parent | 59b89cfac8c3e0402b8e3c27cca8990674b8a5e3 (diff) | |
download | limox-ad882d60b7dabeb4d4ece6435c2fad9f23ab821f.tar limox-ad882d60b7dabeb4d4ece6435c2fad9f23ab821f.tar.zst limox-ad882d60b7dabeb4d4ece6435c2fad9f23ab821f.zip |
Implement byte-based logging for RX
This commit uses an io.TeeReader to achieve the same goal for RX like in
the previous commit for TX.
-rw-r--r-- | xmpp/encoder_decoder.go | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/xmpp/encoder_decoder.go b/xmpp/encoder_decoder.go index 6a37c42..e7eeaf8 100644 --- a/xmpp/encoder_decoder.go +++ b/xmpp/encoder_decoder.go @@ -11,8 +11,7 @@ import ( type encoderDecoder struct { session *session tx *xml.Encoder - st *xml.Decoder // server transport decoder - sl *xml.Encoder // server log encoder + rx *xml.Decoder terminator chan bool } @@ -25,10 +24,8 @@ func newEncoderDecoder(s *session) encoderDecoder { ed.tx = xml.NewEncoder(w) ed.tx.Indent("", " ") - ed.st = xml.NewDecoder(s.transport) - - ed.sl = xml.NewEncoder(os.Stdout) - ed.sl.Indent("S: ", " ") + r := io.TeeReader(s.transport, os.Stdout) + ed.rx = xml.NewDecoder(r) return ed } @@ -59,16 +56,8 @@ func (ed *encoderDecoder) run() { case <-ed.terminator: return default: - t, err := ed.st.Token() + t, err := ed.rx.Token() if t != nil && err == nil { - err = ed.sl.EncodeToken(t) - if err != nil { - log.Println("Could not encode to server stream log") - } - err = ed.sl.Flush() - if err != nil { - log.Println("Could not flush server stream log") - } c := xml.CopyToken(t) ed.session.rx <- c } |