Skip to content

Instantly share code, notes, and snippets.

@ddelange
Created April 17, 2025 18:00
Show Gist options
  • Save ddelange/e7b37b705b8a05d6390e4824fb220ed4 to your computer and use it in GitHub Desktop.
Save ddelange/e7b37b705b8a05d6390e4824fb220ed4 to your computer and use it in GitHub Desktop.
Logging basicConfig with environment variables
import logging
import os
import sys
LOGGING_LEVEL = getattr(logging, os.environ.get("LOGGING_LEVEL", "INFO"))
LOGGING_FORMAT = os.environ.get(
"LOGGING_FORMAT",
"%(asctime)s:%(levelname)-7s %(filename)20s:%(lineno)-4d %(name)s:%(message)s",
)
logging.basicConfig(level=LOGGING_LEVEL, format=LOGGING_FORMAT, stream=sys.stdout)
logging.info("Logging set to %s", LOGGING_LEVEL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment