-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Customize smtp traffic log format #136
Comments
Hi @Dennis-Zhang-SH, thanks for opening this issue. Can you elaborate a bit more what you are actually requesting? The standard logger we ship with go-mail does support formatted logging already - in fact it's even required by the interface that |
Hi I mean the hard coded "C <-- S:" and "C --> S:", it would be nice to have self defined format, say "Sent: msg" and "Reply (code): msg" |
Thanks for clarifying. I'll see what would be the best approach for this |
So I see two possible options here:
What are your thoughts? |
I think maybe providing the raw logs would be better? people can manipulate the logs by themselves. |
That's an option, but the communication is two-way. How would we differentiate between message sent by the client or by the server without making the logging interface much more complex? |
something like this? type Logs struct {
Recv []RecvLog
Sent []string
}
type RecvLog struct {
Code int
Msg string
}
func (l *Logs) Debug() {
for _, m := l.Recv {
logger.Debug("s ---> c", m)
}
} then you can setup a new Debug func to overwrite the default debug func. |
The logging system in the smtp.go and log package has been refactored. A new custom log type `Log` was introduced, that includes the message direction, format and arguments. The `Logger` interface and the `Stdlog` implementation were modified to accept this new type. This change provides a clearer understanding of message direction inside logs, allowing for easier debugging and reduced complexity. This change does not affect features or disrupt user functionality. Additionally, it allows for custom implementations of the log.Logger interface to without being forced to use the C --> S/C <-- S direction logging.
I've proposed a change to the If we accept this change, we need to mark it as breaking, even though I don't think that many users are actually using their own logging interface in their implementations. |
the default log format should be "C ---> S:" and it should be able to overwrite, but now it's like "C ---> S: myformat", if you don't mind, I can work on this later and try to find a better way to solve this, and probably won't be a breanking change, |
The default format for the |
Oh okay, that should fix it, thanks for your work and appologize for my late reply. |
In the updated version of msgwriter.go, an additional error handling process has been included. If an error is detected when creating a new part in the message writer, this error is stored and prevents executing the writeBody function. This fixes nil pointer dereference in `mw.writeBody` if an error occured previously
Are you ok with the proposal? In that case i would merge it to main then. |
Yes I am fine with it, you can close this issue after merged. |
Is your feature request related to a problem? Please describe.
No response
Describe the solution you'd like
pass a format string and logging with the format.
Describe alternatives you've considered
fork and chang the log message in forked repo
Additional context
No response
The text was updated successfully, but these errors were encountered: