Skip to content

How to split logs of different levels to different outputs?  #678

@bunyk

Description

@bunyk

I use logrus and I'm requested to to write info and debug log messages to stdout, and warning, errors fatals and panics to stderr.

Currently I see no straightforward solutions for this, as Logger has only one Out.

I was thinking about writing writer that parses log message and writes to Stdout or Stderr depending on it's level, but this could break when log formatter is changed.

So I changed my mind thinking about creating "/dev/null" Writer, and

log.SetOutput(NullWriter{}) // Send all logs to nowhere by default

Then write hooks that write logs to stderr and stdout, and register them for appropriate levels. (Something like this)

Which lead me to the question why have both Out setting and Hooks? Hooks alone would be enough with default hook for stderr and possibility to delete and add another hooks. And if there was already hook for standart outputs, my task would be much simpler. (So this could be regarded as a feature request).

Or what would developer of this library do to solve this?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions