Meta data doesn't get passed to info object after the update
See original GitHub issuePlease tell us about your environment:
- _
winston
version: “^3.0.0”,-
winston@2
-
winston@3
-
- _
node -v
outputs: v9.8.0 - Operating System? (Linux)
What is the problem?
After updating to the latest version of Winston, 2 days ago, meta data is not added to the info object anymore in some cases!
EXAMPLE 1 (This one works fine!!):
If you log meta data like this, meta becomes part of ‘message’ object, so it seems to work fine.
logger.error('This is a test', { number: 123 });
‘console.log’ of the ‘info’ object looks like this:
{ number: 123,
level: '\u001b[31merror\u001b[39m',
message: 'This is a test',
timestamp: '2018-06-28T09:42:04.036Z',
[Symbol(level)]: 'error',
[Symbol(splat)]: [ { number: 123 } ],
[Symbol(message)]: '{"number":123,"level":"error","message":"This is a test"}' }
EXAMPLE 2 (This one doesn’t seem to work properly!!):
If there is an additional argument included ( in this case ‘first’ ), meta data becomes an empty array in the info object and also it is not anywhere else in the ‘message’ object at all.
logger.error('This is a test %s', 'first', { number: 123 });
‘console.log’ of the ‘info’ object looks like this:
{ level: '\u001b[31merror\u001b[39m',
message: 'This is a test first',
timestamp: '2018-06-28T09:48:46.616Z',
meta: [],
[Symbol(level)]: 'error',
[Symbol(splat)]: [ 'first' ],
[Symbol(message)]: '{"level":"error","message":"This is a test %s"}' }
What do you expect to happen instead?
As you can see, meta data doesn’t exist in the ‘info’ object at all, so there is no way to access it and print it to the console or to log it into the file or anything. This used to work fine before i updated winston npm package 2 days ago.
Thanks for the good work guys, the project is amazing! Best regards!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:5 (2 by maintainers)
Top GitHub Comments
I did some more tests and things are even more out of order regarding ‘meta data’, at least this is how i feel. If you test the examples below and you print out the ‘info’ object for each of them, you should see that ‘meta’ sometimes appear as info object property ,sometimes it appears as part of the ‘message’ object and if you test example 2 in my first post, you should see that sometimes meta data isn’t passed to the info object at all.
// meta data
logger.error('This is a test', { number: 123 });
// 1 splat + meta data
logger.error('This is a test %s', 'first', { number: 123 });
// 2 splats
logger.error('This is a test %s %s', 'first', { number: 123 });
// Interpolation: meta data
logger.error(`Testing interpolation`,{ name: 'john'});
// Interpolation: variable + meta data
logger.error(`Testing ${12345} interpolation`,{ name: 'john'});
I think ‘meta’ property should always appear in the ‘info’ object at the exactly same place, otherwise it is really hard to check something like: if (info.meta) …do something… because info.meta exists in some scenarios, but appears elsewhere (in the different place or even different form) in another scenario and in some scenarios (which i believe is a bug) is not passed to info object at all.
I had to add lot code in my “logger configuration file” just to detect, if meta data exists or not (in all those different scenarios in the examples above), which i believe is totally unnecessary if the properties of info object were consistent. I simply think it would be easiest if we could always check against: if (info.meta) …do something… else …do something…
I hope that makes sense and keep up the good work, best regards!
Sounds like a good idea to me.