Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

We'd like to use Winston for our logging in Node.js. But, we can't figure out how to have two log files: one for just errors, and one for everything else.

Doing this the naive way doesn't work, however: adding multiple winston.transports.File transports gives an error.

Others have run into this problem, with vague hints of a solution, but no real answer.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
578 views
Welcome To Ask or Share your Answers For Others

1 Answer

Unfortunately, the patch that pesho mentioned seems to be still not included in the official version (see stephenbeeson's comment in the pull request #149).

So, I used a workaround instead. As winston compares the name attributes, you can fool it by defining the name yourself:

winston = require 'winston'

logger = new winston.Logger
  transports: [
    new winston.transports.File
      name: 'file#debug'
      level: 'debug'
      filename: '/tmp/debug.log'
    new winston.transports.File
      name: 'file#error'
      level: 'error'
      filename: '/tmp/error.log'
  ]
logger.error 'error' # both logs
logger.debug 'debug' # on debug log

Maybe not elegant, but at least it works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...