xmppo / go-xmpp

Go XMPP Library (From Yasuhiro Matsumoto and based on the code from Russ Cox)
https://golang.org/
BSD 3-Clause "New" or "Revised" License
526 stars 170 forks source link

Print sent stanzas in debug mode. #141

Closed mdosch closed 1 year ago

mdosch commented 2 years ago

When debugging issues it would often be useful to also see the messages that are sent. I didn't find a way to do it as simple as you managed to do it for received stanzas but from the different approaches I tried this seems to be the best one.

I purposely didn't enable printing stanzas sent during auth to prevent people from accidentally pasting their credentials when showing logs.

mdosch commented 2 years ago

Any comments on this?

Neustradamus commented 1 year ago

@mattn: Have you seen this PR?

mattn commented 1 year ago

Thank you

mdosch commented 1 year ago

Can you please elaborate what issues you see? I am using this for a while now and have not faced any issues.

vcabbage commented 1 year ago

@mdosch Are you using multiple clients concurrently? Each new client will assign to StanzaWriter, right?

mdosch commented 1 year ago

Ah, indeed I use only one connection. Unfortunately I don't have time right now to figure out an alternative implementation of printing debug output. Do you have any idea?

vcabbage commented 1 year ago

I think the simplest option would be to add a stanzaWriter io.Writer field to the Client struct and do something like this:

if o.Debug {
    c.p = xml.NewDecoder(tee{c.conn, DebugWriter})
    c.stanzWriter = io.MultiWriter(c.conn, DebugWriter)
} else {
    c.p = xml.NewDecoder(c.conn)
    c.stanzWriter = c.conn
}
mdosch commented 1 year ago

Thanks, I will look into it.

Am 22. Mai 2023 14:35:24 UTC schrieb Kale Blankenship @.***>:

I think the simplest option would be to add a stanzaWriter io.Writer field to the Client struct and do something like this:

if o.Debug {
  c.p = xml.NewDecoder(tee{c.conn, DebugWriter})
  c.stanzWriter = io.MultiWriter(c.conn, DebugWriter)
} else {
  c.p = xml.NewDecoder(c.conn)
  c.stanzWriter = c.conn
}