meta data bug
See original GitHub issueHi there,
version: 3.0.0-rc1
There is a nasty bug, which prevents metadata (e.g. info.meta) to be accessible inside formatter unless there is at least one splat along with meta data.
Reproducing this bug is simple:
// THIS IS THE EXAMPLE THAT DOESN’T WORK AS EXPECTED
// If you try to log meta data, it will NOT work (u won’t be able to access info.meta inside formatter),
// unless there is at least one ‘splat’ included.
logger.info('my message', { reason: 'whatever', promise: 'whenever' });
// THIS EXAMPLE WORKS FINE
// In order to properly log meta data along with ‘my message’ you are forced to include at least one splat.
logger.info('my message%s', 'It needs one splat that i do not need', { reason: 'whatever', promise: 'whenever' });
https://github.com/winstonjs/winston/blob/3b6da2c00b24a90bb6c99f2ae69fa8302f9f03d9/lib/winston/logger.js#L173
line 173:
const info = Object.assign({}, meta, { [LEVEL]: level, level, message: msg });
Should be changed to:
const info = Object.assign({}, { [LEVEL]: level, level, message: msg, meta });
With this change ,info.meta is accessible inside formatter regardless if there are any ‘splats’ included or not and it is now also sorted properly if you do a console.log on the info object (same order with splats or without any splat).
Can someone please test this bug and if the ‘code fix’ looks good, please apply this patched code to the project.
Best regards, Jim
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
@teneon I included your fix in this pull request https://github.com/winstonjs/winston/pull/1229
Thanks for highlighting this @teneon. This is not a bug. Hopefully this example clears it up for you: https://github.com/winstonjs/winston/pull/1235