question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Include name of standard library loggers

See original GitHub issue

Use case

In order to locate the source of a log message, the name of the standard library logger often gives a hint of where it’s coming from, as it’s a convention to use logging.getLogger(__name__) to name the logger (see https://docs.python.org/3/howto/logging-cookbook.html#using-logging-in-multiple-modules for an example).

When following the FAQ guide step “How can I enable powertools logging for imported libraries? (permalink)”

(btw, logging.logger() needs to be changed to logger.getLogger("my.precious.logger"))

I will get a log message of

{
    "level": "INFO",
    "location": "<module>:12",
    "message": "test message",
    "timestamp": "2022-06-29 11:44:51,630+0000",
    "service": "abc-def",
    "sampling_rate": "0.1"
}

I am missing the name of the logger. In the above case it’s not that difficult to locate where the log originated from, but take this example:

{
    "level": "DEBUG",
    "location": "parse:239",
    "message": "Response headers: {'x-amzn-RequestId': '446775e4-6fbc-59a4-8c88-2ed253d21d82', 'Date': 'Wed, 29 Jun 2022 11:40:30 GMT', 'Content-Type': 'text/xml', 'Content-Length': '378'}",
    "timestamp": "2022-06-29 11:40:30,927+0000",
    "service": "abc-def",
    "sampling_rate": "0.1",
    "cold_start": true,
    "function_name": "DevMyLambda-SFunction5A4552-bTFQOMC2LFTH",
    "function_memory_size": "128",
    "function_arn": "arn:aws:lambda:eu-west-1:0123456789:DevMyLambda-SFunction5A4552-bTFQOMC2LFTH",
    "function_request_id": "9963e4d9-40fb-444a-9023-5ab5c973da5c",
    "xray_trace_id": "1-62bc3a2b-6bb3afff1f9cf2d77b20c5fc"
}

It’s difficult to see what library emitted that log message.

Solution/User Experience

Ideally, when aws-lambda-powertools-python is logging from standard library loggers, it should include the logger name as well.

Alternative solutions

Maybe this can be achieved using `LambdaPowertoolsFormatter` but I don't see the key available under https://awslabs.github.io/aws-lambda-powertools-python/latest/core/logger/#standard-structured-keys

Acknowledgment

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:17 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
kbakkcommented, Oct 4, 2022

Sounds like a good improvement, thanks for adding this! 😀

1reaction
heitorlessacommented, Jul 1, 2022

Merged. We’ll revisit the addition of the logger_name field when using copy_config_to_registered_logger function after our pause ends 😃

Thank you one more time @kbakk and congrats on your first contrib!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

logging — Logging facility for Python — Python 3.11.1 ...
The key benefit of having the logging API provided by a standard library module is that all Python modules can participate in logging,...
Read more >
Standard Library Logging - structlog 22.3.0 documentation
structlog ships a stdlib-specific bound logger that mirrors the log methods of standard library's logging.Logger with correct type hints. If you want to...
Read more >
Logging sources - 1.58.0
The library provides a way to declare global loggers that can be accessed pretty much like std::cout . In fact, this feature can...
Read more >
Python Logging Basics - The Ultimate Guide To Logging
Python Logging Basics. This article covers the basics of using the standard logging module that ships with all Python distributions.
Read more >
Python Logging Guide - Best Practices and Hands-on ...
Request a Demo ... The Python standard library provides a logging module as a solution to log events from ... Logging levels can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found