winston
Versatile, multi-transport logging library for Node.js — log to console, files, databases, and external services simultaneously.
winston
Node.jsVersatile, multi-transport logging library for Node.js — log to console, files, databases, and external services simultaneously.
Fit
Bundle (gzip)
38.0 kB
149.7 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Production applications need logs sent to multiple destinations — console during development, files in staging, and a service like Datadog or Loggly in production — with different formats and log levels per destination.
What It Does
Winston lets you configure multiple transports (Console, File, HTTP, Stream) on a single logger. Each transport can have its own log level, format, and error handling. Custom formats using winston.format.combine() let you add timestamps, colorize output, or serialize to JSON.
Installation
npm install winstonUsage Example
import winston from 'winston';
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.Console({ format: winston.format.colorize({ all: true }) }),
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
new winston.transports.File({ filename: 'logs/combined.log' }),
],
});
logger.info('Server started', { port: 3000 });
logger.error('Unhandled exception', { err: error.message });Related packages
Role and attribute based access control (RBAC + ABAC) for Node.js with a fluent, readable API.
bcryptjsNode.jsPure JavaScript bcrypt password hashing — no native dependencies, same API as bcrypt, works anywhere Node.js runs.
bullmqNode.jsPremium message queue and job scheduler for Node.js backed by Redis — reliable background job processing with retries, priorities, and rate limiting.
casbinNode.jsA powerful authorization library that supports RBAC, ABAC, ACL and more via configurable policy models.
dotenvNode.jsLoad environment variables from a `.env` file into `process.env` — the standard way to manage configuration in Node.js apps.