Skip to content

Instantly share code, notes, and snippets.

@felixhummel
Last active July 22, 2025 07:23
Show Gist options
  • Save felixhummel/fe3ae6244c2f271d8cc7bc8cb161b2fa to your computer and use it in GitHub Desktop.
Save felixhummel/fe3ae6244c2f271d8cc7bc8cb161b2fa to your computer and use it in GitHub Desktop.
structlog config with loglevel name
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "structlog>=25.1.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