Logrus: Feature request: discard logger

Created on 20 Mar 2018  路  2Comments  路  Source: sirupsen/logrus

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

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:

logger := logrus.New()
if !wantLogs {
    logger.Out = ioutil.Discard
}

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drewwells picture drewwells  路  3Comments

demizer picture demizer  路  4Comments

rogierlommers picture rogierlommers  路  5Comments

SergeiVasilenko picture SergeiVasilenko  路  3Comments

kubistika picture kubistika  路  3Comments