logger-generator
Generates production-grade, high-availability logging modules for any programming language (Python, TypeScript, Go, etc.). Enforces best practices like rotation, formatting, and minimal dependencies.
When & Why to Use This Skill
The Logger Generator skill automates the creation of production-grade, high-availability logging modules for multiple programming languages including Python, TypeScript, and Go. It ensures robust observability by enforcing industry best practices such as automated log rotation, standardized ISO formatting, and dual-channel output (console and file) with minimal external dependencies.
Use Cases
- Bootstrap new software projects with standardized, production-ready logging utilities to ensure immediate observability.
- Upgrade legacy codebases by replacing basic print or console.log statements with structured, thread-safe logging modules.
- Standardize log formats and collection policies across polyglot microservices to simplify centralized log analysis.
- Implement automated log rotation and retention policies to prevent production server disk space issues.
- Configure high-performance, async-safe logging for concurrent applications in Go or Node.js.
| name | logger-generator |
|---|---|
| description | Generates production-grade, high-availability logging modules for any programming language (Python, TypeScript, Go, etc.). Enforces best practices like rotation, formatting, and minimal dependencies. |
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
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).