Logger Generator Skill
This skill guides the creation of robust, "out-of-the-box" logging utilities for any software project. It ensures that generated logging modules meet production standards for observability, reliability, and ease of use, regardless of the target programming language.
When to Use This Skill
Use this skill when:
- •Setting up a new project (Python, Node.js, Go, Rust, etc.) and need a reliable logger.
- •Replacing simple
printorconsole.logstatements with a proper logging system. - •The user asks for a "logging module", "log util", or "logger setup".
- •You need to standardize log collection across different services in a polyglot repository.
Core Requirements Checklist
Any logger generated using this skill MUST satisfy the following criteria unless explicitly overridden:
- •Stand-alone Module: Must be a single, portable file (e.g.,
logger.py,logger.ts,logger.go). - •Dual Channel Output:
- •Console: With COLOR coding for log levels (Human readable).
- •File: Plain text, structured, standard encoding (Machine readable).
- •Complete Log Levels:
DEBUG,INFO,WARN/WARNING,ERROR,FATAL/CRITICAL. - •Standardized Format:
- •Timestamp (ISO-like or
YYYY-MM-DD HH:MM:SS.mmm). - •Log Level (Aligned).
- •Source Location (File + Line Number).
- •Component/Module Name.
- •Message.
- •Timestamp (ISO-like or
- •Log Rotation:
- •Automatic rotation (Time-based/Daily or Size-based).
- •Automatic cleanup (Retention policy, e.g., keep last 30 days).
- •Configuration:
- •Support default "Zero Config" (Global Singleton).
- •Support custom instances (Configurable paths, levels).
- •Support UTF-8/Unicode characters specifically.
- •Robustness:
- •Thread-safe / Async-safe where applicable.
- •No external dependencies if possible (prefer Standard Lib). If external libs are needed (e.g., Node.js), minimize them.
- •Traceability:
- •Error logs must support printing Stack Traces / Tracebacks.
Language-Specific Implementation Guides
Python
- •Library:
logging(Standard Lib). - •Rotation:
logging.handlers.TimedRotatingFileHandler. - •Colors: ANSI escape codes in a custom
logging.Formatter. - •Pattern: Singleton instance with
getLogger().
TypeScript / Node.js
- •Library: Prefer
winstonfor robust features, or a custom wrapper aroundfs+consolefor zero-dependency needs. - •Rotation:
winston-daily-rotate-file(if using winston). - •Colors:
chalkor simple ANSI codes. - •Pattern: Export a
Loggerclass and a defaultloggerinstance.
Go (Golang)
- •Library:
log/slog(Standard Lib > 1.21) orzap(High perf). - •Rotation: Go stdlib does not rotate. Use
gopkg.in/natefinch/lumberjack.v2for file rotation. - •Pattern:
MultiWriterfor splitting output toos.Stdoutand file.
Example Output Format
text
2024-03-20 10:15:30.123 | INFO | main.py:45 | auth_service | Server started on port 8080 2024-03-20 10:15:32.456 | ERROR | db.py:102 | db_pool | Connection failed (Retrying...)
Generation Protocol
- •Identify Language: Confirm the target language (Python, TS, Go, etc.).
- •Select Strategy: Choose between "Standard Library Only" (preferred for simple scripts) or "Industry Standard Package" (preferred for large apps).
- •Generate Code: Write the module implementing the [Core Requirements Checklist].
- •Verify: Ensure usage examples cover:
- •Basic usage (Global logger).
- •Configuration (Custom file paths).
- •Exception handling (Try-Catch logging).