question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'debug' level is getting directed to stderr instead of stdout

See original GitHub issue

Setup

  • winston version 2.2.0
  • node version 4.4.7

Repro Steps

  1. Save the following into a file named app.js:

    'use strict';
    
    const winston = require('winston');
    const log = new winston.Logger({
    levels: {
      error: 3,
      warning: 4,
      notice: 5,
      info: 6,
      debug: 7,
    },
    transports: [
      new (winston.transports.Console)({
        level: 'debug',
      }),
    ],
    });
    
    log.error('test error');
    log.warning('test warning');
    log.notice('test notice');
    log.info('test info');
    log.debug('test debug');
    
  2. Run the app with command: node app.js > app.log 2>err.log

  3. View the contents of err.log and notice that the log.error and log.debug output both ended up in there (former expected, latter not expected). View the contents of app.log and notice that the log.warning, log.notice, and log.info output all ended up in there (as expected).

  4. Edit app.js to find/replace all 4 instances of ‘debug’ with any other word - e.g. ‘debugz’.

  5. Run the app (again) with (the same) command: node app.js > app.log 2>err.log

  6. Notice how all the stuff ends up in the same file, except that the log.debugz output is now in app.log and not in err.log.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

28reactions
rhbeckercommented, Sep 23, 2016

Found the answer here: https://github.com/winstonjs/winston/blob/master/docs/transports.md

… i.e. setting the levels to log to stderr instead of stdout via stderrLevels transport option.

FWIW, I didn’t find it very intuitive that this option would default to ['error', 'debug'], but that may be based on my own ignorance of how that default would make sense.

I’ll let someone on the project close this issue after reading this feedback, but I need no additional help.

10reactions
jasperkuperuscommented, May 10, 2017

Debug logging does not indicate an error in my eyes. Good that it can be changed via stderrLevels, but shouldn’t the default be ['error'] in stead of ['error', 'debug']?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to redirect stdout and stderr to logger in Python
It works both with python2 and 3, in case you log to a file (e.g. logging.basicConfig(filename='example.log', level=logging.DEBUG). But if you want e.g. logging...
Read more >
debug output is written to stderr instead of stdout #5187 - GitHub
Redirecting the stderr to stdout is a possible solution, but this will of course also redirect real errors.
Read more >
Redirect stdout and stderr to a logger in Python
I'm writing a daemon and needed a method of redirecting anything that gets sent to the standard out and standard error file descriptors...
Read more >
Linux : how to redirect stdout & stderr to logger?
The first part ( echo info; >&2 echo critical ) simulate a program that output both on stdout and stderr.
Read more >
BASH Shell Redirect stderr To stdout ( redirect stderr to a File )
Explains how to redirect stderr to stdout to a file or vice versa in ... apt-get -y install lxd wireguard vnstat expect mariadb-server...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found