-
Notifications
You must be signed in to change notification settings - Fork 421
Duplicated logs for loggers with same service name #249
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
Comments
Hi @dnlopes, thank you for raising this issue -- This is in fact a bug as using the same logger name, or simply not passing one and relying on It's coming from here as we're configuring an existing Logger as opposed to returning it: https://github.com/awslabs/aws-lambda-powertools-python/blob/835789e959e6f563e0e6f9611b549a3d2a1b2e59/aws_lambda_powertools/logging/logger.py#L154 As for Will ping once a fix is ready and thank you again |
Hey @heitorlessa , thanks for the quick reply. The problem I mentioned regarding when using |
Yes, I'm aware it's not trivial. We're relying on hierarchical support, so if the child is created first (it will in the import example, and it is expected), the hierarchy will be fixed when the parent is created -- The only issue here is if there are log statements as part of the import, but then this is the same when using std logger. What I've got a fix and test coverage for that now, I'm releasing a patch shortly |
I didn't know about that hierarchy would eventually self-heal, that's nice to hear. Nevertheless, if you are fixing this in the product itself, I think I would rather wait for it. When you say releasing a patch shortly, you mean within the next hours, or you mean in the next release (days/weeks)? |
Patch is ready - could you double check the PR above @dnlopes in case I missed anything obvious? Once you approve I'll kick off the release and should be ready within a few minutes. |
I already approved, looks OK, altough the PR is broken (seems not related with the fix itself) Thanks for the quick action. |
fix: prevent touching preconfigured loggers #249
This is now available in PyPi with the version 1.9.1. I'm closing this now, and appreciate the bug reporting and the PR validation once again :) Enjoy the public holidays PS: On the PR, that was merely Codecov endpoints not being available as it happens from time to time. |
In my code base, all modules have a logger with a well-known service name, which is used across my whole application. This name is passed via the POWERTOOLS_SERVICE_NAME environment variable. While doing so, I'm having duplicated log entries that scales with the number of modules invocation which declare a logger. Example: if my flow passes by 5 modules that declare
logger = Logger()
then I will have 5 duplicated entries in my logs.Expected Behavior
When using
logger = GetLogger()
with the same service name, I was expecting to not have logs duplications.Current Behavior
When using
logger = GetLogger()
with the same service name, logs duplication occurs. I believe I already identified the root cause: when a logger is instantiated, even though the underlying logger object is the same, a new handler is being created for the logger, which results in one handler being registered in eachlogger = GetLogger()
invocation.Steps to Reproduce (for bugs)
The following snippet will reproduce the issue.
However, if I change the loggers to have different names, no duplication occurs.
I understand I can achieve what I want with the child=True flag, but that leads to some other issues like: how to decide which loggers are child or not.
I feel this is rather a common use case, so I don't understand why there are no reports of this behavior.
What am I missing? Is this by design?
Environment
Thanks,
David
The text was updated successfully, but these errors were encountered: