terrylica avatar

Python Logging Best Practices

This is a practical reference for Python logging that starts with the lightest approach and scales up only when needed. The standout pattern is a zero-dependency dual-channel setup: print statements go to systemd journald for ops, while a separate JSONL file captures structured telemetry for machine analysis. It includes a smart token fingerprinting technique that logs only a mid-section slice of secrets, avoiding the regex redaction trap entirely. The decision tree helps you pick between lightweight patterns, loguru, structlog, or stdlib based on your actual scale and deployment model. Good for anyone tired of overengineered logging setups or dealing with credentials accidentally hitting logs.

skills.sh installs
406
GitHub stars
2
last updated
Aug 21, 2026

Install

$ npx -y skills add terrylica/cc-skills --skill python-logging-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Files

Python Logging Best Practices

Self-Evolving Skill: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.

When to Use This Skill

Use this skill when:

  • Setting up Python logging for any service or script
  • Configuring structured JSONL logging for analysis
  • Implementing log rotation
  • Choosing between lightweight (zero-dep) and full-featured logging
  • Adding logging to containerized, systemd, or local applications

Overview

Unified reference for Python logging patterns optimized for machine readability (Claude Code analysis) and operational reliability. Starts with the lightest viable approach and scales up only when needed.

Decision Heuristic: Start Light, Scale Up

Is it < 5 services on a single machine, < 1 event/sec?
  YES → Lightweight Pattern (print + JSONL telemetry)
  NO  → Is it containerized / serverless?
    YES → stdout JSON (any library), no file rotation
    NO  → Is OTel tracing required?
      YES → structlog + OTel
      NO  → loguru (CLI tools) or stdlib RotatingFileHandler

Sponsors

Details

Repository
github.com/terrylica/cc-skills
Categories
DevOps & CI/CD, Python
First seen
Jun 3, 2026

More from terrylica/cc-skills

All 15
1bobmatnyc avatarkubernetesbobmatnyc/claude-mpm-skillsKubernetes operations playbook for deploying services: core objects, probes, resource sizing, safe rollouts, and fast kubectl debugging397skills.sh installs
2evoscientist avatarexperiment-pipelineevoscientist/evoskillsGuides structured 4-stage experiment execution with attempt budgets and gate conditions: Stage 1 initial implementation (reproduce baseline), Stage 2 hyperparam396skills.sh installs
3levnikolaevich avatarln-781-build-verifierlevnikolaevich/claude-code-skillsBuilds all detected projects and verifies successful compilation. Use when checking that a bootstrapped project compiles.381skills.sh installs
4levnikolaevich avatarln-771-logging-configuratorlevnikolaevich/claude-code-skillsConfigures structured JSON logging with Serilog (.NET) or structlog (Python). Use when adding logging to backend projects.376skills.sh installs
5sanjay3290 avatarazure-devopssanjay3290/ai-skillsManage Azure DevOps projects, work items, repos, PRs, pipelines, wikis, test plans, security alerts, variable groups, environments/approvals, branch policies, a369skills.sh installs
6personamanagmentlayer avatardocker-expertpersonamanagmentlayer/pclExpert-level Docker containerization, image optimization, and container orchestration. Use this skill for building efficient Docker images, managing containers,368skills.sh installs