logging-best-practices

Solid

Structured logging with proper levels, context, PII handling, centralized aggregation. Use for application logging, log management integration, distributed tracing, or encountering log bloat, PII exposure, missing context errors.

DevOps & Infrastructure 168 stars 27 forks Updated 4 weeks ago MIT

Install

View on GitHub

Quality Score: 89/100

Stars 20%
74
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Logging Best Practices Implement secure, structured logging with proper levels and context. ## Log Levels | Level | Use For | Production | |-------|---------|------------| | DEBUG | Detailed debugging | Off | | INFO | Normal operations | On | | WARN | Potential issues | On | | ERROR | Errors with recovery | On | | FATAL | Critical failures | On | ## Structured Logging (Winston) ```javascript const winston = require('winston'); const logger = winston.createLogger({ level: process.env.LOG_LEVEL || 'info', format: winston.format.combine( winston.format.timestamp(), winston.format.json() ), defaultMeta: { service: 'api-service' }, transports: [ new winston.transports.Console(), new winston.transports.File({ filename: 'error.log', level: 'error' }) ] }); // Usage logger.info('User logged in', { userId: '123', ip: '192.168.1.1' }); logger.error('Payment failed', { error: err.message, orderId: '456' }); ``` ## Request Context ```javascript const { AsyncLocalStorage } = require('async_hooks'); const storage = new AsyncLocalStorage(); app.use((req, res, next) => { const context = { requestId: req.headers['x-request-id'] || uuid(), userId: req.user?.id }; storage.run(context, next); }); function log(level, message, meta = {}) { const context = storage.getStore() || {}; logger.log(level, message, { ...context, ...meta }); } ``` ## PII Sanitization ```javascript const sensitiveFields = ['password', 'ssn', 'creditCard', 'token']...

Details

Author
secondsky
Repository
secondsky/claude-skills
Created
7 months ago
Last Updated
4 weeks ago
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category