Logrus: [Question]: output to the STDOUT and File at the same time

Created on 10 Jan 2018  路  6Comments  路  Source: sirupsen/logrus

Could you please advise how I can write simultaneously to stdout and log file?
Is it possible? From the description, it is not obvious and I can't find correspondent method.

Most helpful comment

You should try io.MultiWriter

mw := io.MultiWriter(os.Stdout, logFile)
logrus.SetOutput(mw)

All 6 comments

You should try io.MultiWriter

mw := io.MultiWriter(os.Stdout, logFile)
logrus.SetOutput(mw)

Great, thank you very much!!!

please add to docs

The downside is that you have to stick to the same formatter for both files... :(

@fser - I solved having different formatters for stdout and the log file using this snippet: https://github.com/sirupsen/logrus/issues/784#issuecomment-403765306

@kramer65 How did you accomplish two different formatters using vanilla logrus? (ie: without rotatefilehook)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kubistika picture kubistika  路  3Comments

penhauer-xiao picture penhauer-xiao  路  4Comments

UnAfraid picture UnAfraid  路  5Comments

psmason picture psmason  路  4Comments

zhangdaoling picture zhangdaoling  路  4Comments