Structlog Config banner
iloveitaly iloveitaly

Structlog Config

Development community

Description

A comprehensive structlog configuration with sensible defaults for development and production environments, featuring context management, exception formatting, and path prettification.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

README

[![Release Notes](https://img.shields.io/github/release/iloveitaly/structlog-config)](https://github.com/iloveitaly/structlog-config/releases) [![Downloads](https://static.pepy.tech/badge/structlog-config/month)](https://pepy.tech/project/structlog-config) ![GitHub CI Status](https://github.com/iloveitaly/structlog-config/actions/workflows/build_and_publish.yml/badge.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Opinionated Defaults for Structlog

Logging is really important. Getting logging to work well in python feels like black magic: there's a ton of configuration across structlog, warnings, std loggers, fastapi + celery context, JSON logging in production, etc that requires lots of fiddling and testing to get working. I finally got this working for me in my [project template](https://github.com/iloveitaly/python-starter-template) and extracted this out into a nice package.

Here are the main goals:

  • High performance JSON logging in production
  • All loggers, even plugin or system loggers, should route through the same formatter
  • Structured logging everywhere
  • Pytest plugin to easily capture logs and dump to a directory on failure. This is really important for LLMs so they can easily consume logs and context for each test and handle them sequentially.
  • Ability to easily set thread-local log context
  • Nice log formatters for stack traces, ORM (ActiveModel/SQLModel), etc
  • Ability to log level and output (i.e. file path) by logger for easy development debugging
  • If you are using fastapi, structured logging for access logs
  • Improved exception logging with beautiful-traceback

Installation

uv add structlog-config

Usage

from structlog_config import configure_logger

log = configure_logger()

log.info("the log", key="value")

# named logger just like stdlib
impor