Logrus: When hook is initialised successfully, disable logging to stdout

Created on 19 Feb 2016  路  5Comments  路  Source: sirupsen/logrus

Most of the time I'm logging to a Redis host, which pipes messages straight to an ELK stack. I'm wondering if it is possible to disable all output to stdout/err at the time a hook is initialised successfully.

For example:

hook, err := logredis.NewHook("localhost", 6379, "my_redis_key", "my_app_name")
if err == nil {
    log.AddHook(hook)
    log.DisableStdOut()
}

So once the hook is in use, disable all output to stdout. Is this possible now?

Most helpful comment

@rogierlommers you can set the output to be ioutil.Discard. See:

All 5 comments

@rogierlommers you can set the output to be ioutil.Discard. See:

Thanks! I have updated my hook readme; included your comment.

I know it is a closed issue but logrus.SetOutput(ioutil.Discard) doesn't work.
However, log.Out = ioutil.Discard does the job.

@mirdhyn SetOutput will work on the global logger, but you're right that a logger created with New will need to have its output changed this way.

Thank you for clarifying this @aybabtme :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

piotrkowalczuk picture piotrkowalczuk  路  4Comments

drewwells picture drewwells  路  3Comments

salvador-dali picture salvador-dali  路  5Comments

demizer picture demizer  路  4Comments

anoop-nair picture anoop-nair  路  3Comments