Set up application logger
✓Works with OpenClaudeYou are a backend/full-stack developer setting up structured logging for an application. The user wants to configure a production-ready logger with appropriate log levels, output formats, and transport mechanisms.
What to check first
- Check if
winstonorpinois already installed vianpm list winstonornpm list pino - Verify Node.js version supports your chosen logging library (Node 12+)
- Determine if logs should go to console, files, or external services (Datadog, CloudWatch, etc.)
Steps
- Install a logging library:
npm install winston(ornpm install pinofor high-performance logging) - Create a
logger.jsorlogger.tsfile in yoursrc/orconfig/directory - Configure log levels:
error,warn,info,http,debug,silly(Winston) orfatal,error,warn,info,debug,trace(Pino) - Set up transports (Winston) or streams (Pino) to define where logs are written (console, file, or external service)
- Add timestamp formatting to each log entry for traceability
- Configure log format as JSON for machine parsing or readable text for development
- Export the logger instance and import it wherever logging is needed
- Set the log level via environment variable (e.g.,
LOG_LEVEL=debug) so it's configurable per environment
Code
// logger.js (Winston setup)
const winston = require('winston');
const path = require('path');
const logLevel = process.env.LOG_LEVEL || 'info';
const isDevelopment = process.env.NODE_ENV === 'development';
const logger = winston.createLogger({
level: logLevel,
format: winston.format.combine(
winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
winston.format.errors({ stack: true }),
isDevelopment
? winston.format.simple()
: winston.format.json()
),
defaultMeta: { service: 'my-app' },
transports: [
new winston.transports.Console({
format: isDevelopment
? winston.format.combine(
winston.format.colorize(),
winston.format.printf(
({ timestamp, level, message, ...meta }) =>
`${timestamp} [${level}]: ${message} ${
Object.keys(meta).length ? JSON.stringify(meta, null, 2) : ''
}`
)
)
: winston.format.json(),
}),
new winston.transports.File({
filename: path.join('logs', 'error.log'),
level: 'error',
format: winston.format.json(),
}),
new winston.transports.File({
filename: path.join('logs', '
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related General / Utility Skills
Other Claude Code skills in the same category — free to download.
Env Setup
Set up development environment from scratch
Gitignore Generator
Generate .gitignore for any project type
NPM Publish
Prepare and publish npm package
Error Boundary
Create error boundary components
Feature Flag
Implement feature flag system
Config Manager
Create application configuration manager
Date Time Helper
Create date/time utility functions
String Utils
Create string manipulation utilities
Want a General / Utility skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.