skills/logging-guide/SKILL.md
Implement structured logging with proper log levels and sensitive data handling. Use when: adding logging, debugging, setting up observability. Keywords: logging, log level, structured logging, observability.
npx skillsauth add asiaostrich/universal-dev-standards logging-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Language: English | 繁體中文
Version: 1.1.0 Last Updated: 2026-05-26 Applicability: Claude Code Skills
Core Standard: This skill implements Logging Standards. For comprehensive methodology documentation, refer to the core standard.
This skill helps implement consistent, structured, and actionable application logs across all environments.
| Level | Code | When to Use | Production | |-------|------|-------------|------------| | TRACE | 10 | Very detailed debugging info | Off | | DEBUG | 20 | Detailed debugging info | Off | | INFO | 30 | Normal operation events | On | | WARN | 40 | Potential issues, recoverable | On | | ERROR | 50 | Errors that need attention | On | | FATAL | 60 | Critical failures | On |
Is it debugging only? → DEBUG (off in prod)
Normal operation completed? → INFO
Something unexpected but OK? → WARN
Operation failed? → ERROR
App cannot continue? → FATAL
| Level | Examples | |-------|----------| | TRACE | Function entry/exit, loop iterations, variable values | | DEBUG | State changes, configuration values, query parameters | | INFO | App startup/shutdown, user actions, scheduled tasks | | WARN | Deprecated API, retry attempts, resource approaching limits | | ERROR | Failed operations, caught exceptions, integration failures | | FATAL | Unrecoverable errors, startup failures, lost critical resources |
{
"timestamp": "2025-01-15T10:30:00.123Z",
"level": "INFO",
"message": "User login successful",
"service": "auth-service",
"environment": "production"
}
{
"timestamp": "2025-01-15T10:30:00.123Z",
"level": "INFO",
"message": "User login successful",
"service": "auth-service",
"environment": "production",
"trace_id": "abc123",
"span_id": "def456",
"user_id": "usr_12345",
"request_id": "req_67890",
"duration_ms": 150,
"http_method": "POST",
"http_path": "/api/v1/login",
"http_status": 200
}
Use snake_case and prefix with domain:
| Domain | Common Fields | |--------|---------------| | HTTP | http_method, http_path, http_status, http_duration_ms | | Database | db_query_type, db_table, db_duration_ms, db_rows_affected | | Queue | queue_name, queue_message_id, queue_delay_ms | | User | user_id, user_role, user_action | | Request | request_id, trace_id, span_id |
For complete standards, see:
For AI assistants, use the YAML format files for reduced token usage:
ai/standards/logging.ai.yaml// Bad
logger.info('Login attempt', { password: userPassword });
// Good
logger.info('Login attempt', { password: '***REDACTED***' });
// Good - mask partial
logger.info('Card processed', { last_four: '4242' });
{
"level": "ERROR",
"message": "Database connection failed",
"error_type": "ConnectionError",
"error_message": "Connection refused",
"error_code": "ECONNREFUSED",
"stack": "Error: Connection refused\n at connect (/app/db.js:45:11)..."
}
Always include:
logger.error('Failed to process order', {
error_type: err.name,
error_message: err.message,
order_id: orderId,
user_id: userId,
retry_count: 2,
stack: err.stack
});
{"timestamp":"2025-01-15T10:30:00.123Z","level":"INFO","message":"Request completed","request_id":"req_123","duration_ms":45}
2025-01-15T10:30:00.123Z [INFO] Request completed request_id=req_123 duration_ms=45
| Environment | Level | Strategy | |-------------|-------|----------| | Development | DEBUG | All logs | | Staging | INFO | Most logs | | Production | INFO | Sampling for high-volume |
File-based log sinks MUST set both rotation triggers — time-based and size-based. Default size caps in popular libraries (Serilog 1 GB, log4j/Winston/Python RotatingFileHandler no cap) cause silent data loss in production.
✓ rollingInterval: Day # time-based
✓ fileSizeLimitBytes: 104857600 (100 MB) # size-based
✓ rollOnFileSizeLimit: true # roll, do NOT drop
✓ retainedFileCountLimit: ≥ N*7 # N = max rolls/day
When a log file reaches ≥ 90% of fileSizeLimitBytes at expected end-of-day, investigate the noise root cause (noisy retry loop / unbounded debug logging / stack-trace flood) before raising the cap.
Full specification with per-language recipes (.NET Serilog / Python / Java log4j2 / Node Winston) and the real-incident failure-mode reference: see Log File Rotation Policy in the core standard.
rollingInterval: Day or equivalent)fileSizeLimitBytes + rollOnFileSizeLimit: true)retainedFileCountLimit ≥ N×7 (N = max rolls/day)This skill supports project-specific configuration.
CONTRIBUTING.md for logging guidelinesIf no logging standard found:
CONTRIBUTING.md:## Logging Standards
### Log Levels
- DEBUG: Development only, detailed diagnostic info
- INFO: Normal operations (startup, user actions, tasks)
- WARN: Unexpected but recoverable situations
- ERROR: Failures that need investigation
### Required Fields
All logs must include: timestamp, level, message, service, request_id
### Sensitive Data
Never log: passwords, tokens, credit cards, SSN
After /logging completes, the AI assistant should suggest:
日誌標準已掌握。建議下一步 / Logging standards understood. Suggested next steps:
- 根據日誌指南在程式碼中實作結構化日誌 ⭐ Recommended / 推薦 — 立即將日誌標準應用到專案 / Apply logging standards to the project immediately
- 執行
/errors設計錯誤碼以配合日誌系統 — 讓錯誤追蹤更有效率 / Make error tracking more efficient- 執行
/sdd將可觀測性需求納入規格 — 確保日誌需求在規格中有定義 / Ensure logging requirements are defined in specs
| Version | Date | Changes | |---------|------|---------| | 1.1.0 | 2026-05-26 | Added: Log File Rotation section with cross-link to core standard rotation policy; Rotation checklist (XSPEC-232) | | 1.0.0 | 2025-12-30 | Initial release |
This skill is released under CC BY 4.0.
Source: universal-dev-standards
development
[UDS] 扫描代码库的调试残留与代码质量问题;可自动修正安全模式。 Use when: before committing, during PR review, or periodic codebase cleanup. Keywords: sweep, debug cleanup, console.log, debugger, TODO, ts-any, code quality, 扫描, 清理.
tools
[UDS] 从规格衍生 BDD 场景、TDD 骨架或 ATDD 表格
development
[UDS] 识别重复流程并以正确的开发深度构建 Skill
tools
[UDS] AI 辅助 git push 安全层:质量门禁 + 协作护栏。 Use when: pushing commits, force pushing, pushing to protected branches, pushing feature branches. Keywords: git push, force push, protected branch, quality gate, push receipt, PR automation, 推送, 保护分支, 质量门禁.