-
Notifications
You must be signed in to change notification settings - Fork 146
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
Maintenance: add tests for child logger attributes #483
Comments
Hello there! As part of the work on the
During two rounds of improvements (PR #1178 and PR #1267) implementation was changed and weak spots of unit tests were uncovered and necessary adjustments were added. Especially the test in the last PR covers all child logger attributes assesses against non-default values which was an issue with previous tests.
I would also add an example with a child logger where it implicitly inherits some parent's attributes, like |
Hey Sergei, thank you for looking into this and for the assessment. I agree that perhaps we can improve this section of the docs.
In regards to this I would say that as a user you can overwrite any of the settings that can also be set via constructor, which are the default ones, any persistent attributes, and the log formatter.
Maybe we could update the example in this section to not only show that you can overwrite but also that other attributes are passed down to the child. Maybe we could set service name and/or persistent attribute - similar to this: import { Logger } from '@aws-lambda-powertools/logger';
// This logger has a service name, some persistent attributes
// and log level set to INFO
const logger = new Logger({
serviceName: 'serverlessAirline',
logLevel: 'INFO',
persistentLogAttributes: {
aws_account_id: '123456789012',
aws_region: 'eu-west-1',
},
});
// This other logger inherits all the parent's attributes
// but the log level, which is now set to ERROR
const childLogger = logger.createChild({
logLevel: 'ERROR'
}); We should also modify the CloudWatch log excerpt (other tab).
I would add a "tip" box (see here) in the section that talks about custom log formatter instead saying something like: "When you set a custom formatter it is propagated/passed down to any children logger" (worded more nicely maybe)
We have another issue tracking the creation of a "recommended / best practices" section in the docs to cover this type of topic. I would defer this last point to that issue/discussion (perhaps we could add a comment under that issue linking to here to not forget), but I would leave it out for now as it's not strictly related to how the logger works. What do you think? |
Thank you for the proposals, I like them! So I'm going to make a PR, and let's continue with the discussion there. |
|
Description of the feature request
Problem statement
During a 1:1 feedback session it emerged that the current behavior of
Logger.createChild
might not be immediately clear to people approaching the library for the first time. Likewise, the current unit test cases, while reaching 100% coverage, might use some improvements to cover all cases.The steps to complete this issue should be (in this order):
createChild
? If not, what would you add?Summary of the feature
N/A
Code examples
Unit tests for the feature: link
Implementation for the feature: link
Benefits for you and the wider AWS community
Describe alternatives you've considered
Additional context
N/A
Related issues, RFCs
N/A
The text was updated successfully, but these errors were encountered: