Hey there,
Thanks for this great library :smile:
My apologies if this was considered and rejected before - I searched the issues but didn't find anything. I wanted to suggest the addition of a new constructor that could create a dummy logger that would discard all logs.
For example, something like:
func Discard() *Logger {
l := New()
l.Out = ioutil.Discard
l.Level = PanicLevel
}
Then consuming code could have a reasonable default, e.g.:
logger := logrus.Discard()
if wantLogs {
logger = logrus.New()
}
An alternative is to provide a dummy implementation of logrus.FieldLogger, which would probably perform better since it doesn't have to do anything with the input values. It's a small convenience but I think it would be useful to others. These solutions are similar to, but more straightforward than, the suggestion in https://github.com/sirupsen/logrus/issues/662.
I'm happy to contribute this, but would need some guidance implementing it.
Cheers,
Jonathan
Not sure why the suggestion in #662 is not enough. I really can't see the value of adding a new constructor in the library when you can do easily:
logger := logrus.New()
if !wantLogs {
logger.Out = ioutil.Discard
}
Indeed this is quite easy to discard all traces this way, I don't think we need this added constructor
Most helpful comment
Not sure why the suggestion in #662 is not enough. I really can't see the value of adding a new constructor in the library when you can do easily: