winston-daily-rotate-file

A Winston transport that rotates log files daily, by size, and with automatic compression

Library
npm
v5.0.0
929 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
46 /100 Fair
Development Activity 0
Maintenance 20
Community 76
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
74 /100 Good
Architecture 76
Code Quality 80
Innovation 55
Learning Curve 85

winston-daily-rotate-file is a transport plugin for the Winston logging library that writes logs to a file that automatically rotates on a daily basis (or a configurable pattern), with optional size-based rotation, gzip compression of rotated files, and automatic pruning of old logs by age or total count. It’s a common addition to any Node.js service using Winston that needs disk-based logs without unbounded file growth or manual log-rotation tooling.

The package integrates directly into Winston’s transport interface, so it’s added alongside console or other transports in a standard Winston logger configuration rather than requiring a separate logging pipeline.

What You Get

  • A drop-in Winston transport following the standard winston.transports interface
  • Daily rotation by default, with configurable date patterns and size-based rotation thresholds
  • Optional gzip compression of rotated log files
  • Automatic pruning of old logs by max file count or max age
  • Events (rotate, new, archive, logRemoved) for hooking into the rotation lifecycle

Common Use Cases

  • Node.js services writing persistent file-based logs that need automatic daily rotation instead of one ever-growing log file
  • Compliance/audit logging setups that need retained, dated, and eventually pruned log archives
  • Reducing disk usage on long-running servers by combining size-based rotation with gzip compression
  • Hooking into rotation events to trigger log shipping/upload to external storage right after a file rotates

Under The Hood

Architecture: The core (daily-rotate-file.js, ~370 lines) extends Winston’s TransportStream base class and computes the current file name from a moment-style date pattern on each write, opening a new file stream when the pattern’s rendered value changes (i.e. when the day rolls over) or when a size threshold is exceeded. Rotation, archiving (gzip), and pruning are handled as side effects triggered from within the same write path rather than a separate background scheduler process.

Tech Stack: Plain Node.js/CommonJS, depending directly on winston-transport for the base class contract and using Node’s built-in zlib/fs for compression and file I/O rather than external rotation binaries.

Code Quality: The test/transport-tests.js suite covers rotation-by-date, rotation-by-size, and pruning behavior, plus a transport.worker.js used to validate behavior when logging from multiple processes. TypeScript definitions (index.d.ts) are bundled for consumer type safety, though the project has had no commits since March 2024.

API Design: Configuration is a flat options object passed straight into Winston’s standard transport-array pattern (new transports.DailyRotateFile({...})), so anyone already familiar with Winston can add rotation with a single new transport entry — a low learning curve given prior Winston familiarity.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers