Skip to content

The aws_lambda_powertools Logger breaks Python's standard library logging functionality. #194

Closed
@techdragon

Description

@techdragon

Enabling normal logging from dependent python libraries that use the standard library logging mechanism does not work.

Expected Behavior

Setting the log level of a package you are using in your code, should produce the appropriate log outputs.
For example:

import logging
logging.getLogger('boto3').setLevel(logging.DEBUG)

should result in the boto3 library producing logs.

Current Behavior

This does nothing when using the aws_lambda_powertools due to the Logger removing the standard library root logging handler.

Possible Solution

  1. There are existing libraries for building complex, customisable and powerful logging workflows, with both JSON formatting and context injection on top of the standard library logging. Two prominent examples are:

  2. The combination of heitorlessa@6b8be5d
    and the solution to Get the logger to respect module hierarchy as a normal logger #97 currently only allows for the aws_lambda_powertools Logger to handle logging from code "in" the lambda or written directly for use in a lambda. It silences all standard library logging.

  3. @heitorlessa stated in Get the logger to respect module hierarchy as a normal logger #97 that you wanted to maintain backwards compatibility

If you have ideas on how we could comply with hierarchy in logging while maintaining backwards compatibility in the UX,

then went on to suggest that if this cannot be done

we can solve this problem differently using something like Borg to share configuration between instances, while additional instances can have additional or override existing configuration

I've done a fair amount of logging code in the past ( a public example here ) and in light of points 1,2 and 3 I personally would cut my losses, follow semantic versioning, bump the major version number and replace the entire logging functionality with something new. Python logging has established patterns and while to quote @heitorlessa "the UX we wanted to provide" may have compelling business or developer experience reasoning behind it... your chosen approach appears to be at odds with the way Python's standard library logging works.

Other than "not breaking backwards compatibility"... Are you able to more thoroughly explain the constraints you used to decide on the current logging approach?

Since I'm looking at writing my own replacement for the aws_lambda_powertools Logger since it doesn't support standard library logging and I'd be willing to submit it as a PR, I have two key questions to help shape what I write.

  1. Do you have any restrictions on what dependencies you can accept in this project?
  2. What was the UX you wanted to provide by choosing the current logger design?

Steps to Reproduce (for bugs)

This is only an example using boto3, all dependent libraries using standard library logging will have the same behaviour.

  1. Add code like this before using the boto3 library.
import logging
logging.getLogger('boto3').setLevel(logging.DEBUG)
  1. Try to do something with the boto3 library.

Environment

  • Powertools version used: v1.6.1
  • Packaging format (Layers, PyPi): Both
  • AWS Lambda function runtime: Python 3.8
  • Debugging logs Not applicable here.

How to enable debug mode**

# paste logs here

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions