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.

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

See original GitHub issue

Please tell us about your environment:

  • winston version?
    • winston@2
    • winston@3
  • node -v outputs: v10.4.1
  • Operating System? macOS High Sierra v10.13.5
  • Language? ES6

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?

  • The migration doc should mention this fundamental change in behavior and how to resolve it:
    • Multiple arguments are treated differently
    • Objects as message are not pretty printed
    • Error Object is ignored (I saw there’s an open issue for that)
    • Formatters order matters
  • I think Winston should support the multiple arguments notation, as it is a very common usage of console.log and really is much easier to use when you need to log a string and then an Object, etc. (specifically when using the Console transport).
  • The new formatters should yield the previous behavior when using the same setup

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
nemoznycommented, Jun 27, 2018

+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

  • coloring doesn’t work
  • simple format output doesn’t work (no JSON)
  • printing out objects (JSON) doesn’t work - I don’t see any reason why use custom formater with JSON.stringify
  • or combination of the above

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

0reactions
indexzerocommented, Jun 27, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing migration filters that are replaced with filter_null may ...
Problem/Motivation Whever I try the upgrade, it hangs at 38%. Checking the error log, I see multiple entries with the message "Missing ...
Read more >
Safer logging methods for f-strings and new-style formatting
An additional advantage to a new set of logger methods is that it's possible to migrate away from the old % -style string...
Read more >
How do I run a code formatter over my source without ...
No, you misunderstand. The git filter-branch command allows me to edit lines, without changing the author of the revision, so git blame still ......
Read more >
Migrate from ASP.NET Core 2.2 to 3.0 | Microsoft Learn
Learn how to migrate an ASP. ... NET Core SDK version, update its version property to the 3.0 ... Json based formatter does...
Read more >
Version Migration Guide - Rasa
If you still have training data in Markdown format then the recommended ... Until Rasa 3.0 type annotations were not required in custom ......
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