Get the FREE Ultimate OpenClaw Setup Guide →

python-logging

Scanned
npx machina-cli add skill narumiruna/agent-skills/python-logging --openclaw
Files (1)
SKILL.md
1.2 KB

Python Logging

Overview

Choose the logging system based on project needs. Core principle: stdlib logging for libraries and ecosystem integration, loguru for fast, simple app/CLI logging.

Quick Reference

NeedUse
Library or long-lived servicestdlib logging
Simple app or CLIloguru
Integrations (Sentry/OTel)stdlib logging

Decision Rules

Use stdlib logging when:

  • Building a reusable library
  • You need handler hierarchies or integration with ops tooling

Use loguru when:

  • You want minimal setup and readable output
  • You are building a small app or CLI

Example

Stdlib logger setup:

import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info("App started")

Common Mistakes

  • Forcing loguru in a reusable library.
  • Mixing two logging systems without a clear boundary.

Red Flags

  • Logging recommendations with no rationale for library vs app use.

References

  • references/logging.md - stdlib logging patterns
  • references/loguru.md - loguru patterns

Source

git clone https://github.com/narumiruna/agent-skills/blob/main/skills/python-logging/SKILL.mdView on GitHub

Overview

Python Logging helps you decide between stdlib logging and loguru. Use stdlib logging for libraries and ecosystem integration, and loguru for fast, simple app or CLI logging. This skill guides you to pick the right tool based on project type and goals.

How This Skill Works

Evaluate the project type first: libraries and long-lived services benefit from stdlib logging with hierarchical handlers and ecosystem compatibility, while small apps or CLIs benefit from loguru's minimal setup and readable output. For integrations like Sentry or OTel, stdlib logging is preferred. Avoid mixing systems in the same component and document the boundary.

When to Use It

  • If you're building a reusable library or long-lived service
  • If you're creating a simple app or CLI and want minimal setup
  • If you need integrations (Sentry/OTel) with your logging
  • If you require handler hierarchies or ops tooling integration (stdlib logging)
  • If you want to maintain a clear boundary between library code and application logging

Quick Start

  1. Step 1: Assess project type (library vs app) and integration needs
  2. Step 2: Choose stdlib logging for libraries/integrations or loguru for simple apps, and avoid mixing
  3. Step 3: Implement the chosen system with clear boundaries and document the decision

Best Practices

  • Use stdlib logging for libraries and ecosystem integrations
  • Use loguru for small apps/CLIs with minimal setup and readable output
  • Do not mix two logging systems inside the same component; keep boundaries clear
  • Prefer stdlib logging when integrating with Sentry/OTel for compatibility
  • Document the chosen approach and rationale in project docs

Example Use Cases

  • A reusable library that exposes a module logger via stdlib logging for consumer apps to configure
  • A long-running service using stdlib logging with console and file handlers and central log aggregation
  • A CLI tool using loguru to provide quick, readable logs with minimal boilerplate
  • An application that integrates Sentry/OTel using stdlib logging for unified observability
  • A library refactor that avoids forcing loguru on library users and maintains a clear stdlib boundary

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers