Logging Monitoring

Configuring Python logging library, formatting streams, and managing rotating logs.

Lord1Egypt Updated 2 repo stars

File contents

Logging Monitoring

Overview

Logging provides diagnostic tracking systems in software, helping debug runtime issues without cluttering stdout.

When to Use This Skill

Use to log request statuses, background operations, and track crashes systematically inside files.

Quick Start (with runnable code examples)

import logging
from logging.handlers import RotatingFileHandler

# Set up log formatter
log_fmt = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')

# Set up rotating log files (max 1MB, keeping 3 backups)
handler = RotatingFileHandler("app.log", maxBytes=1000000, backupCount=3)
handler.setFormatter(log_fmt)

logger = logging.getLogger("AppLogger")
logger.setLevel(logging.INFO)
logger.addHandler(handler)

logger.info("Application successfully initialized.")

Advanced Usage

Set up multi-logger inheritance tree, log exception traces automatically using logger.exception(), and configure central diagnostic systems.

Key References

Dependencies

  • Python Standard Library

Lord1Egypt/ai-skillforge/tree/main/js/skills/gemini/logging-monitoring commit 021010f959

Frequently asked questions

npx skillmds@latest add lord1egypt/logging-monitoring-2