Created
April 17, 2025 18:00
-
-
Save ddelange/e7b37b705b8a05d6390e4824fb220ed4 to your computer and use it in GitHub Desktop.
Logging basicConfig with environment variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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