summaryrefslogtreecommitdiff
path: root/xmpp/log.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-01 21:05:03 +0200
committerxengineering <me@xengineering.eu>2023-07-01 21:05:03 +0200
commit322e2c5f24c830282dbd66adbb95a7acf1255c9a (patch)
tree1321563b28a7fc0c8b5748210e802986e965e595 /xmpp/log.go
parent0882d7861ed764cc856f2a6b4572630ec12751bf (diff)
parent6e973cfabe17421748af51856351f83e9856d137 (diff)
downloadlimox-322e2c5f24c830282dbd66adbb95a7acf1255c9a.tar
limox-322e2c5f24c830282dbd66adbb95a7acf1255c9a.tar.zst
limox-322e2c5f24c830282dbd66adbb95a7acf1255c9a.zip
Merge branch 'byte-based-logging'
Logging used to re-encode tokens for receive logging and double-encode tokens for send logging. This had the flexibility to pretty-print the XML. Furthermore it was trivial to prepend a prefix like `S: ` and `C: ` for server and client. This merge moves away from logging based on re-encoding XML tokens. Instead the received or sent bytes are multiplexed to a logger which uses the log module of the standard library to log the XML code. These advantages come with this merge: - [TX] / [RX] instead of C: / S: as prefixes (direction instead of node) - encoding issues can be debugged via the log - everything is now logged via the log module and has timestamps The only disadvantage is that the logged XML is not pretty-printed anymore. This is choosen for the RX stream to not accidentally hide encoding issues and show what is really on the wire. That argument is true for TX aswell and consistency is appreciated anyway.
Diffstat (limited to 'xmpp/log.go')
-rw-r--r--xmpp/log.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/xmpp/log.go b/xmpp/log.go
new file mode 100644
index 0000000..4ac0f88
--- /dev/null
+++ b/xmpp/log.go
@@ -0,0 +1,15 @@
+package xmpp
+
+import (
+ "log"
+)
+
+type logger struct {
+ prefix string
+}
+
+func (l logger) Write(p []byte) (n int, err error) {
+ log.Printf("%s%s", l.prefix, string(p))
+
+ return len(p), nil
+}