summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-01 19:55:11 +0200
committerxengineering <me@xengineering.eu>2023-07-01 19:55:11 +0200
commit59b89cfac8c3e0402b8e3c27cca8990674b8a5e3 (patch)
tree3319ff0764746484c0923282fc0b9aa0fce502ef
parent0882d7861ed764cc856f2a6b4572630ec12751bf (diff)
downloadlimox-59b89cfac8c3e0402b8e3c27cca8990674b8a5e3.tar
limox-59b89cfac8c3e0402b8e3c27cca8990674b8a5e3.tar.zst
limox-59b89cfac8c3e0402b8e3c27cca8990674b8a5e3.zip
Implement byte-based logging for TX
Using an io.MultiWriter it is trivially possible to write encoded tokens to the TCP channel aswell as to stdout. The disadvantage is that it is not possible to inject prefix data like the so far used `C: ` only for stdout and not for the TCP channel. Such a prefix is not wanted in the TCP channel and thus not wanted for both. The solution to get a nice log is to implement a transparent logging middleware which gets the raw TX stream and inserts a prefix at each line before sending to stdout.
-rw-r--r--xmpp/encoder_decoder.go24
1 files changed, 6 insertions, 18 deletions
diff --git a/xmpp/encoder_decoder.go b/xmpp/encoder_decoder.go
index c340b09..6a37c42 100644
--- a/xmpp/encoder_decoder.go
+++ b/xmpp/encoder_decoder.go
@@ -10,8 +10,7 @@ import (
type encoderDecoder struct {
session *session
- ct *xml.Encoder // client transport encoder
- cl *xml.Encoder // client log encoder
+ tx *xml.Encoder
st *xml.Decoder // server transport decoder
sl *xml.Encoder // server log encoder
terminator chan bool
@@ -22,11 +21,9 @@ func newEncoderDecoder(s *session) encoderDecoder {
ed.session = s
- ed.ct = xml.NewEncoder(s.transport)
- ed.ct.Indent("", " ")
-
- ed.cl = xml.NewEncoder(os.Stdout)
- ed.cl.Indent("C: ", " ")
+ w := io.MultiWriter(s.transport, os.Stdout)
+ ed.tx = xml.NewEncoder(w)
+ ed.tx.Indent("", " ")
ed.st = xml.NewDecoder(s.transport)
@@ -44,20 +41,11 @@ func (ed *encoderDecoder) encodeToken(t xml.Token) error {
}
}()
- err = ed.ct.EncodeToken(t)
- if err != nil {
- return err
- }
- err = ed.ct.Flush()
- if err != nil {
- return err
- }
-
- err = ed.cl.EncodeToken(t)
+ err = ed.tx.EncodeToken(t)
if err != nil {
return err
}
- err = ed.cl.Flush()
+ err = ed.tx.Flush()
if err != nil {
return err
}