Closed Dennis-Zhang-SH closed 1 year ago
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 Debugf
, Infof
, Warnf
and Errorf
are satisfied.
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
Debugf
,Infof
,Warnf
andErrorf
are satisfied.
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:
Client
for you to provide the In- and Out logging strings. But that would require adding new fields to the Client and smtp.Client structs, which might be not favourable.What are your thoughts?
So I see two possible options here:
- We can add a new option to the
Client
for you to provide the In- and Out logging strings. But that would require adding new fields to the Client and smtp.Client structs, which might be not favourable.- Since this is very much an edge case, we can check the ENV variables for the in- and out strings directly in the method in the smtp client and if set, we could override the defaults. This would be the most favourable option but might not work in every edge case, neither.
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?
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.
I've proposed a change to the log.Logger
interface as well as to the Stdlog
logger. It breaks the old interface but allows the logging interface to be much more flexible and should allow you to use your own formatting. Feedback is welcome.
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 StdLogger
was not changed. It was C --> S: <format> <message>
before this change. It was only moved from the smtp package to the log package. For you to not use the C --> S
syntax, all you need to do is implement your own Debugf()
function that satisfies the log.Logger
interface and then you can completely skip the C --> S
part or format it in the way you want.
The default format for the
StdLogger
was not changed. It wasC --> S: <format> <message>
before this change. It was only moved from the smtp package to the log package. For you to not use theC --> S
syntax, all you need to do is implement your ownDebugf()
function that satisfies thelog.Logger
interface and then you can completely skip theC --> S
part or format it in the way you want.
Oh okay, that should fix it, thanks for your work and appologize for my late reply.
Are you ok with the proposal? In that case i would merge it to main then.
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