V3: New formatters are not equivalent to old formatters, broken logs after migration
See original GitHub issuePlease 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'));
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'));
Even if I add the simple
formatter, it’s still not the same:
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:
- Created 5 years ago
- Reactions:5
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+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.
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.