{"id":10432,"library":"winston","title":"Winston Logger","description":"Winston is a versatile logging library for JavaScript and Node.js, designed to support multiple transports for logs. It allows flexible configuration of log formatting and levels, decoupling the logging process from storage implementation. The current stable version is 3.19.0, with regular patch and minor releases addressing fixes and new features.","status":"active","version":"3.19.0","language":"javascript","source_language":"en","source_url":"https://github.com/winstonjs/winston","tags":["javascript","winston","logger","logging","logs","sysadmin","bunyan","pino","loglevel","typescript"],"install":[{"cmd":"npm install winston","lang":"bash","label":"npm"},{"cmd":"yarn add winston","lang":"bash","label":"yarn"},{"cmd":"pnpm add winston","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Winston supports both CommonJS (`const winston = require('winston')`) and ES Modules, as it ships TypeScript types and targets modern Node.js environments.","symbol":"winston","correct":"import winston from 'winston'"}],"quickstart":{"code":"import winston from 'winston';\n\nconst logger = winston.createLogger({\n  level: 'info',\n  format: winston.format.json(),\n  defaultMeta: { service: 'user-service' },\n  transports: [\n    // Log all errors to error.log\n    new winston.transports.File({ filename: 'error.log', level: 'error' }),\n    // Log all info and higher to combined.log\n    new winston.transports.File({ filename: 'combined.log' })\n  ]\n});\n\n// Add a console transport if not in production\nif (process.env.NODE_ENV !== 'production') {\n  logger.add(new winston.transports.Console({\n    format: winston.format.simple()\n  }));\n}\n\n// Example logging\nlogger.info('User logged in', { userId: 123 });\nlogger.warn('Deprecated feature used');\nlogger.error('Failed to connect to database', { error: 'Connection refused' });","lang":"typescript","description":"Initializes a Winston logger with file transports for error and combined logs, adding a console transport for non-production environments, and demonstrates various log levels."},"warnings":[{"fix":"Refer to the `UPGRADE-3.0.md` guide in the official documentation for detailed migration instructions.","message":"Winston v3 introduces significant breaking changes compared to v2, including a new API for logger instantiation and transport configuration.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always create your own logger instance using `winston.createLogger()` and configure transports, or explicitly add transports to the default logger before use.","message":"Using the default logger (`require('winston')` or `import winston from 'winston'`) without explicitly adding any transports can lead to high memory usage as logs are buffered indefinitely.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Remove all references to `LogCallback` from your TypeScript code; the associated callback functionality was never executed even prior to its type definition removal.","message":"The `LogCallback` type was removed from Winston's TypeScript definitions in v3.15.0 because the underlying library did not actually support this functionality.","severity":"breaking","affected_versions":">=3.15.0"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Use `winston.createLogger()` to create a logger instance instead of `new winston.Logger()`.","cause":"Attempting to instantiate `winston.Logger` directly, which was common in Winston v2 but is no longer the correct pattern in v3.","error":"TypeError: winston.Logger is not a constructor"},{"fix":"Remove `LogCallback` from your type annotations or function signatures; the type was removed as the underlying functionality was unsupported.","cause":"Your TypeScript code is attempting to use the `LogCallback` type or pass a `LogCallback` where it's no longer expected after v3.15.0.","error":"TS2345: Argument of type 'LogCallback' is not assignable to parameter of type '...' (e.g., 'LogEntry')"},{"fix":"Ensure the user running the Node.js process has appropriate write permissions for the log file directory, or configure Winston to write logs to a different, accessible location.","cause":"The Node.js process does not have write permissions to the directory where Winston is attempting to create or write log files.","error":"Error: EACCES: permission denied, open 'error.log'"}],"ecosystem":"npm"}