Created
July 1, 2025 14:00
-
-
Save felixhummel/fe3ae6244c2f271d8cc7bc8cb161b2fa to your computer and use it in GitHub Desktop.
structlog config with loglevel name
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
#!/usr/bin/env python3 | |
# /// script | |
# requires-python = ">=3.11" | |
# dependencies = [ | |
# "structlog==25.4.0", | |
# ] | |
# /// | |
import os | |
import structlog | |
loglevel_name = os.environ.get("LOGLEVEL", "INFO").upper() | |
structlog.configure( | |
wrapper_class=structlog.make_filtering_bound_logger(loglevel_name), | |
) | |
log = structlog.get_logger() | |
def do_stuff(): | |
log.info("doing stuff") | |
if __name__ == "__main__": | |
do_stuff() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment