Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print sent stanzas in debug mode. #141

Merged
merged 4 commits into from
Mar 2, 2023
Merged

Print sent stanzas in debug mode. #141

merged 4 commits into from
Mar 2, 2023

Conversation

mdosch
Copy link
Collaborator

@mdosch mdosch commented Jul 12, 2022

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
Copy link
Collaborator Author

mdosch commented Jul 20, 2022

Any comments on this?

@Neustradamus
Copy link
Member

@mattn: Have you seen this PR?

@mattn mattn merged commit 9fc0b12 into xmppo:master Mar 2, 2023
@mattn
Copy link
Member

mattn commented Mar 2, 2023

Thank you

} else {
c.p = xml.NewDecoder(c.conn)
StanzaWriter = c.conn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change appears unsafe in the presence of multiple clients. All client instances will assign and write to the same package scope StanzaWriter.

@mattn Can this be reverted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdosch Can you handle this?

@mdosch
Copy link
Collaborator Author

mdosch commented May 22, 2023 via email

@vcabbage
Copy link
Contributor

vcabbage commented May 22, 2023

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

@mdosch
Copy link
Collaborator Author

mdosch commented May 22, 2023 via email

@vcabbage
Copy link
Contributor

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
Copy link
Collaborator Author

mdosch commented May 22, 2023 via email

mdosch added a commit to mdosch/go-xmpp that referenced this pull request May 22, 2023
This got reworked to also work with multiple connections
as pointed out by @vcabbage in
xmppo#141 (comment)
mattn pushed a commit that referenced this pull request Jul 28, 2023
* Rework printing of sent stanzas when debug is enabled

This got reworked to also work with multiple connections
as pointed out by @vcabbage in
#141 (comment)

* Remove StanzaWriter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants