Skip to content

Instantly share code, notes, and snippets.

@felixhummel
Created July 1, 2025 14:00
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 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