kata-python-logging-setup

Standardize secure structured JSON logging for Python applications using Loguru.

Updated Sep 3, 2025
One-click install
npx skills add https://github.com/guardiatechnology/design-system --skill kata-python-logging-setup
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kata-python-logging-setup
Source: https://github.com/guardiatechnology/design-system/tree/main/.claude/skills/kata-python-logging-setup
Command: npx skills add https://github.com/guardiatechnology/design-system --skill kata-python-logging-setup

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of inconsistent, unstructured logging by helping you implement a repeatable Loguru-based pattern that emits reliable JSON records with redaction and correlation for traceability.

Core Features & Use Cases

  • Bootstrap secure logging: Configure Loguru sinks to output both readable and structured JSON, while disabling sensitive diagnostic backtrace/diagnose.
  • Decorator-based instrumentation: Add a @logged decorator that logs enter/exit/error events, captures duration, and supports both sync and async functions.
  • Redaction and payload shaping: Redact sensitive fields and emit consistent JSON payloads (including trace/span/correlation identifiers) with minimal exception exposure.
  • OpenTelemetry + correlation integration: Instrument logging with OpenTelemetry and propagate correlation_id via HTTP middleware.

Quick Start

Ask your AI to implement the Loguru JSON logging bootstrap, the @logged decorator (sync/async), correlation middleware, and the Ruff + AST pre-commit policy to remove inline logger.* calls outside the allowlist.

Frequently Asked Questions about kata-python-logging-setup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up structured JSON logging in Python with Loguru?

You can set up structured JSON logging by configuring Loguru sinks with orjson serialization, applying field redaction, and emitting consistent JSON payloads with trace and correlation identifiers for production traceability.

How do I instrument sync and async Python functions for logging?

You can instrument sync and async Python functions by applying a @logged decorator that automatically logs enter and exit events, captures execution duration, and records errors with minimal exception exposure.

What is the best way to correlate Python logs with OpenTelemetry traces?

The best way to correlate Python logs with OpenTelemetry traces is to wire correlation middleware into HTTP request handling and inject trace and span identifiers directly into your structured JSON log payloads.

How do I prevent sensitive data from appearing in Python application logs?

You prevent sensitive data from appearing in Python application logs by implementing a logging bootstrap with redaction logic that strips sensitive fields and disables diagnostic backtrace output before payloads are serialized to JSON.

How do I enforce a standard Python logging pattern across a backend codebase?

You enforce a standard Python logging pattern by defining a Ruff and AST pre-commit policy that blocks unauthorized inline logger calls outside an approved allowlist, ensuring all logging flows through the decorator workflow.

Does this structured logging approach work with both readable and JSON log outputs?

Yes, this structured logging approach works with both readable and JSON log outputs by configuring Loguru sinks to simultaneously emit human-readable formats and structured JSON records for production pipelines.