Winston: Set Console Transport Default Options (colorize: true)

Created on 18 Dec 2012  ·  4Comments  ·  Source: winstonjs/winston

Hi,
I was looking to use the Console Transport out of box, but also wanted to have pretty colors. As it stands it appears the only way to achieve this is by removing the default Console Transport and adding it back with an options object, a-la:

var log = require('winston');
log.remove(log.transports.Console);
log.add(log.transports.Console, {colorize: true});

I'm looking to set that option without removing, then adding it back.. perhaps something that piggybacks off of the existing winston.addColors(myCustomLevels.colors); but without an argument, which could also let you potentially override the default color scheme, since it looks like you can't do that right now either (I tried):

var log = require('winston');
log.addColors();

Most helpful comment

You can just call the cli() method as well.

All 4 comments

:+1:

I do this enough to wrap it up into a module log-colors

var log = require('log-colors')
log.debug('yay colors', {
  foo: 'bar'
})

I have hacked it that way

app.start 3000, ->
  app.log.loggers.default.transports.console.colorize = true

I suspect it's not very elegant, but it works. There are some other interesting properities like prettyPrint and timestamp. It's important to do it inside app.start callback, as app.log is undefined before that.

You can just call the cli() method as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amiram picture amiram  ·  4Comments

anks333 picture anks333  ·  3Comments

tagyoureit picture tagyoureit  ·  4Comments

Buzut picture Buzut  ·  3Comments

KingRial picture KingRial  ·  3Comments