Skip to main content

The Python logging micropackage

Project description

notch

🪓 The Python logging micropackage

Purpose

You can use notch to quickly configure logging for your Python application. I designed notch to encapsulate and standardize logging configuration for Python applications that are deployed as container workloads. The default settings work in many simple cases, and you can further customize logging behavior with environment variables.

Usage

Import notch and call configure() to configure logging in your application entrypoint.

import notch

notch.configure()

Call configure() as early as possible in your application startup, because notch in turn calls logging.basicConfig() to configure the logging system.

Using the default settings, notch will configure the root logger to send logs to sys.stdout, set the log level to INFO, and set the log format to '%(levelname)s [%(name)s] %(message)s'.

Configuration

You can change the behavior of notch by setting environment variables.

  • LOG_LEVEL: change the log level for the root logger. This can be any level the Python logging module recognizes: DEBUG, INFO (the default), WARNING, ERROR, or CRITICAL.
  • LOG_FORMAT: change the format for log output. Use any placeholders defined in the Python logging documentation.
  • OTHER_LOG_LEVELS: change the log level for loggers other than the root logger. See the explanation below.

Setting log levels for other modules

If you use third-party packages, you may want to set log levels for these packages independently. For example, you may want to see DEBUG logs for your own code, but only WARNING messages for other modules. You can do this by setting the OTHER_LOG_LEVELS environment variable.

The value of this variable should be a module name and a log level separated by a colon. You can set log levels for multiple modules by separating entries with a space.

OTHER_LOG_LEVELS=first_module:WARNING second_module:ERROR

For a concrete example, if your application depends on boto3 but you only want to see errors from boto3-related modules in your logs, configure like this:

OTHER_LOG_LEVELS=boto3:ERROR botocore:ERROR

You can specify submodules as well if you need to be more specific:

OTHER_LOG_LEVELS=apscheduler.scheduler:WARNING

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notch-2025.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notch-2025.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file notch-2025.1.tar.gz.

File metadata

  • Download URL: notch-2025.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for notch-2025.1.tar.gz
Algorithm Hash digest
SHA256 199cdf5b35ca6e53e5097421433c2acd560d35888db4ff31371314eacbff07c4
MD5 d145ee10013d988787d809bb88ee9240
BLAKE2b-256 f63a74b719bea775668ae97396d4efc8afb375b74d0f69303b7d0e6b71be9783

See more details on using hashes here.

Provenance

The following attestation bundles were made for notch-2025.1.tar.gz:

Publisher: publish-release-to-pypi.yaml on williamjacksn/notch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file notch-2025.1-py3-none-any.whl.

File metadata

  • Download URL: notch-2025.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for notch-2025.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a12126dee40015f81b8bb1eda89b076110d2a6537fda01242abfaeb77d892ca3
MD5 3c501d3d8f4578d697573f9579e368cc
BLAKE2b-256 0eecde0949a3eddaebe13264d2ba89cded5c87f92486dd47f15f070581d4bdcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for notch-2025.1-py3-none-any.whl:

Publisher: publish-release-to-pypi.yaml on williamjacksn/notch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page