Skip to content

Bug: Handler registered with addHandler not logging extra keys added by append_keys #2356

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

Closed
leandrodamascena opened this issue Jun 1, 2023 Discussed in #2261 · 2 comments · Fixed by #2334
Closed

Bug: Handler registered with addHandler not logging extra keys added by append_keys #2356

leandrodamascena opened this issue Jun 1, 2023 Discussed in #2261 · 2 comments · Fixed by #2334
Assignees
Labels
bug Something isn't working logger

Comments

@leandrodamascena
Copy link
Contributor

Discussed in #2261

Originally posted by nimish-salve May 15, 2023
aws-lambda-powertools version: 2.15.0

I am trying logger to use 2 handlers.

  1. FileHandler
  2. Streamhandler

When I added extra keys via append_keys, newly registered handlers are not logging extra keys.
Sample code below:

import logging
from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter

file_handler = logging.FileHandler('logs.log')
_LOGGER = Logger(service="test", level=logging.INFO, logger_handler=logging.NullHandler())
#_LOGGER = Logger(service="test", level=logging.INFO, logger_handler=file_handler) # this works

def main():
    file_handler.setFormatter(LambdaPowertoolsFormatter())
    _LOGGER.addHandler(file_handler)
    _LOGGER.append_keys(test="test")
    _LOGGER.info("in main 1")

    stream_handler = logging.StreamHandler()
    stream_handler.setFormatter(LambdaPowertoolsFormatter())
    _LOGGER.addHandler(stream_handler)
    _LOGGER.info("in main 2")

if __name__ == "__main__":
    main()

Whats could be the issue?

This is reproducible even with just 1 handler. If we register the handler while creating the logger itself, it works without any issues. When we explicitly register the handler, it does not work.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jun 1, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2023

This is now released under 2.16.1 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working logger
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants