Winston is a Node.js logging library that routes messages through pluggable transports at configurable severity levels. You create loggers that can write to console, files, databases, or custom backends at once.
Overview
Winston separates what you log from where logs go. Each logger can attach multiple transports, each with its own level threshold, so errors might land in a remote store while informational lines stay on disk or stdout.
You typically start with winston.createLogger, choose npm, syslog, or custom level maps, and chain formatters from the logform module for JSON, timestamps, labels, colorized console output, and printf-style templates. Child loggers inherit settings while overriding metadata.
The core treats loggers and transports as object-mode streams carrying structured info objects with level and message fields plus arbitrary metadata. Built-in transports cover common Node file and console targets, and you can implement a transport with a single log method.
Additional capabilities include profiling timers, log querying on supported transports, streaming interfaces, optional handling of uncaught exceptions and promise rejections, and silent modes for tests. A default exported logger exists for apps that want one shared instance without custom setup.
Key features
- Multiple transports per logger
- Per-transport severity levels
- Composable log formats
- Custom logging level schemes
- Child loggers with metadata
- Uncaught exception handlers
- Built-in console and file targets
- Custom transport API
Use cases
- Structured logging in Node services
- Splitting error and debug destinations
- Colorized development console output
- Centralizing logs before shipping to analytics