-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix bug in overriding default metadata in child loggers. #1598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug in overriding default metadata in child loggers. #1598
Conversation
Some reviews on this would be much appreciated! I also have an in-progress branch to implement accessing loggers created via the child function by an ID. Between these two things I could clean up my use of winston by a respectable amount. |
This is much better, but still has some issues. I'm including a code sample and sample output using both Stable winston 3.2.0 and the PR code. This code includes usage examples from the root logger and from child loggers because I have realized that there are issues with both functionality and they are deeply related. The Codeconst winston = require('winston');
const rootLogger = winston.createLogger({
level: 'debug',
levels: winston.config.npm.levels,
defaultMeta: {
component: 'ROOT'
},
transports: [
new winston.transports.Console({
format: winston.format.printf((info) => `[${info.level}] [${info.component}] ${info.message}`)
})
]
});
const child = rootLogger.child({
component: 'CHILD'
});
console.log('#ROOT\n\n##This group should say [ROOT]')
rootLogger.info('1. root info string');
rootLogger.log({
level: 'info',
message: '2. root info obj'
});
rootLogger.log('info', '3. root info string (level, message)'); // broken
console.log('\n##Next line should say [ROOT2]');
rootLogger.log({
level: 'debug',
message: '4. root log override component',
component: 'ROOT2'
}); // broken
console.log('\n#CHILD\n\n#Everything below here should say [CHILD]');
child.info('5. root info string');
child.log({
level: 'info',
message: '6. root info obj'
});
child.log('info', '7. root info string (level, message)'); // broken
console.log('\n##Next line should say [CHILD2]');
child.log({
level: 'debug',
message: '8. root log override component',
component: 'CHILD2'
}); // broken Winston 3.2.0
PR 1598
Issues, as I observe themThere are two issues, and they show up on both root and child loggers as of this PR.
For the first issue, I think the code needs to call _addDefaultMetadata on the object passed to Please let me know if you need more info |
This is SUPER helpful. I'll pull this test locally, find the discrepancies and see what I can come up with. I'll add a few new tests as well as I don't believe I added any for the |
@kbirger So digging into the remaining issues, it's specifically an issue with the log method. I'm hesitant to modify it as it is written as is to be backwards compatible with previous versions. I'll see what I can come up with. It's primarily centered around them modifying objects in place, instead of returning the modified objects. Edit: Would you be interested in tag-teaming it with me? I've got it 90% there but changes cause regressions across the board which I was worried about. |
@maverick1872 sure thing. I'd be happy to. let me know how we can best do that. edit: also, one of the main maintainers should probably look at this before it gets accepted anyway, and they'd be in the best place to say whether we violate any backwards compatibility. I would think this would be fine, since it doesn't seem like it would be desired behavior and we aren't changing any call signatures. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm supportive of this PR! Seems like child loggers are indeed a bit inconsistent as they stand so would definitely be a win to get everything working consistently.
Dropped a few questions/comments, lmk how I can help, happy to re-review when this is ready to go. @maverick1872 @kbirger feel free to hop on the winston gitter channel if you'd like to have any real-time-ish discussions about this PR. Thanks!
@DABH Thanks for the review and comments. I believe I have answered all of them as of yet. I hope to dig back into this later this week when I'm on vacation. |
Any news on this PR |
@mjurincic I apologize. Life/work caught up to me very quickly (even while on vacation) and I haven't had many free cycles to sit down and revisit this. I will see if I can't address @DABH's comments this weekend and hopefully get it pushed through sooner rather than later. |
Just hit this while trying to use child loggers. Anything I can do to help this along? |
768994b
to
9d0e5e9
Compare
@DABH Is there anyway I can get you to re-review this? |
Any reason why this hasn't been merged? This still just awaiting a review from @DABH ? |
@ryanlewis Yes that is correct. One of the Project Maintainers needs to give it approval. @indexzero could you maybe look this over and give it approval? |
At this point I'm considering Winston a dead package as it appears that the current maintainers are no longer actively supporting any aspect of it. I've seen a couple issues raised, trying to determine the status of the package, only to be shutdown without any indication of the future of the project. I'm happy to assist (in some capacity) in maintaining a fork if there is a desire for it. Otherwise I'll likely start looking for alternatives personally. |
|
When creating a child logger with overrides for
defaultMeta
properties they do not actually override. Is due to the fact that the child logger is overriding thewrite
function which is inappropriate. It should actually be overriding how the default metadata is being added to the log statement. I will have test cases incoming to prove functionality. All existing test cases are passing.This should address issue #1596