Skip to content

winston

A Node.js logging library that sends logs to multiple places like the console or files.

Stars
24.5k
Forks
1.9k
Licence
MIT
Language
JavaScript
Last update
4 months ago
Type
Library

What it is

winston is a JavaScript logging library for Node.js. It records messages from your program and sends them to one or more destinations, called transports, such as the console or a log file. You can set severity levels and formats so that, for example, errors go to a file while everything goes to the console.

  • Write error-level logs to error.log and all info-level logs to combined.log
  • Log to the console only in non-production environments using NODE_ENV
  • Add per-request metadata with logger.child({ requestId })
  • Capture uncaught exceptions and promise rejections to a log file

Great for

  • Node.js developers who need structured or file-based application logs
  • Teams that want different log levels sent to different destinations
  • Projects that need custom log formats or custom transports
  • Services that want per-request metadata via child loggers

Not ideal for

  • Browser-only front-end code, since the README describes a Node.js library (reason: no browser usage is documented)
  • People who only need a quick console.log replacement for a tiny script (reason: setup involves creating a logger and transports)
  • Projects needing a hosted log-search service (reason: winston is a library and does not provide a server or dashboard)
Step-by-step guide: how to use winstonInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js

    Install winston from npm

    npm install winston
  2. 2

    Run it

    • Install the package with npm install winston
    • Require it with const winston = require('winston');
    • Create a logger with winston.createLogger and at least one transport
    • Call logger.info('Hello') or another level method to write a log
  3. 3

    Get the most out of it

    • Use winston.format.json() for machine-readable logs and winston.format.simple() for console output
    • Set separate levels on File transports to split error and combined logs
    • Use logger.child() to attach request-specific metadata, keeping the caveat in mind
    • Use logger.configure() or add()/remove() to change transports at runtime
    • Handle uncaught exceptions and rejections with the documented Exceptions and Rejections sections

Downloads

Strengths

  • Supports multiple transports at different log levels
  • Formats can be combined and customized
  • MIT license and widely used, with 24,527 GitHub stars

Trade-offs

  • The README warns that .child may be buggy if you extend the Logger class
  • The default logger has no transports, and the README says leaving it that way may cause high memory usage
  • Documentation applies to winston@3; 2.x docs are separate

How it compares

ProjectStarsTypeLevelUpdatedBest for
winston (this)24.5kLibraryintermediate4 months agoNode.js developers who need structured or file-based application logs
pino18.3kLibrarybeginner30 days agoNode.js backend developers who want structured JSON logs

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.