-
Notifications
You must be signed in to change notification settings - Fork 421
copy_config_to_registered_loggers results in duplicate logs when using with existing loggers #1073
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
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
@heitorlessa I will look at this today's evening. There was PR created by @houbie #1001 to exclude source logger from a list. |
If I understand #1001 correctly, that is about the source logger being excluded. And from what I understand, the source logger is the Lambda Powertools logger, from which the configs are copied, right? The problem I'm having, is that the logs from another library are duplicated. They appear once properly formatted as JSON, and once as plain text (as per the original config) |
yeah this seems different @dandydev. A logging filter would likely be the solution. Without revisiting the code, this typically happens when you have multiple handlers (we might not be removing existing handlers), or when the root logger is configured and logs get propagated hierarchically (we have a filter on this). Thanks a lot @mploski !! |
I've searched high and low, and the library that instantiates the logger I mentioned in my bug report, doesn't create any handlers. So that cannot be it. Anyways, thanks for picking this up! I'm excited that there's already a PR open to fix this! |
We're looking into this tomorrow @dandydev :) Should have a patch release by EOW (the latest). |
Super swift! Amazing! |
This is now released under 1.25.4 version! |
Since updating to the newly released package, I see this in my logs:
and nothing more. This is the relevant code: from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging import utils
logger = Logger()
utils.copy_config_to_registered_loggers(source_logger=logger, exclude={'sqlalchemy'})
@logger.inject_lambda_context(log_event=True)
@event_parser(model=S3Model, envelope=envelopes.SqsEnvelope)
def handler(event, context):
... @heitorlessa @mploski do you know what is going on? |
@dandydev Looking at this, will ping you later today with the status |
Thanks @mploski , much appreciated! |
Apologies for this regression @dandydev, it sounds like the formatter isn't being created in the parent Logger. Michal and I are trying to replicate with and without the log utils, and make a swift release.
|
No apologies necessary! Software engineering is a finicky business :) Thanks for getting on it so quickly! |
Did a quick test and couldn't reproduce it - only differences are Could you share more info on what other loggers you have besides Will try different angles in the meantime def test_inject_lambda_context_with_config_clone(lambda_context, stdout):
# GIVEN an external logger and Logger are initialized
root_logger = logging.getLogger()
handler = logging.StreamHandler(stdout)
handler.setFormatter(logging.Formatter('{"message": "%(message)s"}'))
root_logger.addHandler(handler)
logger = Logger(service=service_name(), stream=stdout)
utils.copy_config_to_registered_loggers(source_logger=logger)
# WHEN a lambda function is decorated with logger
@logger.inject_lambda_context
def handler(event, context):
logger.info("Hello")
handler({}, lambda_context)
# THEN lambda contextual info should always be in the logs
log = capture_logging_output(stdout)
expected_logger_context_keys = (
"function_name",
"function_memory_size",
"function_arn",
"function_request_id",
)
for key in expected_logger_context_keys:
assert key in log # GIVEN Logger is initialized |
Reproduced it - the issue is in the new external logic - it only happens when you add |
We have a fix, @mploski is pushing a PR shortly, and we make a release right after. A functional test was missing so we wouldn't have been able to cover this regression either way. |
This is now released under 1.25.5 version! |
hey @dandydev it's live on PyPi - could you give it a try? |
Can confirm it works! Thanks for the hard work! |
When using
utils.copy_config_to_registered_loggers()
to copy the PowerLogger config to existing loggers created by a library, this results in duplicate log entries in AWS LambdaExpected Behavior
When copying config from the AWS Powertools logger to existing loggers instantiated by a library, I expect the log statements of that library to appear once in the log stream, formatted as JSON
Current Behavior
When copying config from the AWS Powertools logger to existing loggers, I see log statements from existing loggers appearing twice in the log stream: once properly formatted as JSON and once as plain text
Possible Solution
I don't know why is this happening, so I can't really comment on a solution 😅
Steps to Reproduce (for bugs)
Environment
The text was updated successfully, but these errors were encountered: