winstonjs / winston

A logger for just about everything.
http://github.com/winstonjs/winston
MIT License
22.73k stars 1.81k forks source link

V3: New formatters are not equivalent to old formatters, broken logs after migration #1377

Open alexilyaev opened 6 years ago

alexilyaev commented 6 years ago

Please tell us about your environment:

What is the problem?

I've followed the upgrade to 3.0 doc, and when I was done, my logs were broken.

V2 supported multiple arguments to log functions, and using common format options, pretty printed Objects/Arrays/Errors nicely.

So these logs worked in V2:

const consoleLogger = new winston.Logger({
    transports: [
      new winston.transports.Console({
        level: 'info',
        colorize: true,
        prettyPrint: true,
        timestamp: true
      })
    ]
}),

consoleLogger.info({ one: 1, two: 2, three: 3 });
consoleLogger.info(chalk.blue('[TEST]:'), { one: 1, two: 2, three: 3 });
consoleLogger.info(chalk.blue('[TEST]:'), ...['one', 2, { 3: 3 }]);
consoleLogger.error(chalk.blue('[ERR]:'), new Error('Boo face'));
screen shot 2018-06-24 at 18 51 16 screen shot 2018-06-24 at 18 52 47 screen shot 2018-06-24 at 18 51 47

But in V3, multiple arguments are no longer supported, only meta is supported and only as an Object. Plus the equivalent formatters do not yield the same result.

const consoleLogger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.timestamp(),
    winston.format.colorize(),
    winston.format.prettyPrint(),
    // winston.format.simple()
  ),
  transports: [new winston.transports.Console()]
}),

consoleLogger.info({ one: 1, two: 2, three: 3 });
consoleLogger.info(chalk.blue('[TEST]:'), { one: 1, two: 2, three: 3 });
consoleLogger.info(chalk.blue('[TEST]:'), 'string here is ignored');
consoleLogger.info(chalk.blue('[TEST]:'), ...['one', 2, { 3: 3 }]);
consoleLogger.error(chalk.blue('[ERR]:'), new Error('Boo face'));
screen shot 2018-06-24 at 19 27 33

Even if I add the simple formatter, it's still not the same:

screen shot 2018-06-24 at 19 28 02

What do you expect to happen instead?

respinha commented 6 years ago

+1

The documentation is a bit superficial regarding winston.Format and the provided examples such as this one do not result in the expected output.

indexzero commented 6 years ago

PR would be welcome to update that example @respinha-ribeiro. Will take a look at this in depth and see what we can do to make the transition easier.

indexzero commented 6 years ago

Also @alexilyaev – winston does support the multiple argument notation, it's simply not enabled by default because it is a performance hit and as such opt-in.

Use winston.format.splat().

respinha commented 6 years ago

@indexzero I can gladly post a PR but currently I'm unable to understand how to obtain the standard notation. I tried adding winston.format.splat I just get a weird message like the ones shown by @alexilyaev.

tagyoureit commented 6 years ago

I was making the same comments (objects/arrays) aren't formatting the same in the Gitter chatroom. Seems that the previous options.meta isn't treated the same way. Would be great to understand the differences and how to fix moving forward.

nemozny commented 6 years ago

+1

After maybe 2 hours of trying to obtain the same logging format in V3 as in the previous version, I have to say I have to downgrade. I like the custom formatter and format.combine and everything, but either

I just want logger.error("error"), logger.info(object), logger.info(array) and no hustle.

indexzero commented 6 years ago

All of those features work. If you'd like to share a code sample along with your shade that would be much more constructive.

Edit: @nemozny literally every feature you could not get working has an example in the examples/ directory. Please read those and feel free to add any you feel should be there.