node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

winston-daily-rotate-file

winston-daily-rotate-file

NPM version Build Status Dependency Status

A transport for winston which logs to a rotating file each day.

Usage

  var winston = require('winston');
  require('winston-daily-rotate-file');
 
  var transport = new (winston.transports.DailyRotateFile)({
    filename: './log',
    datePattern: 'yyyy-MM-dd.',
    prepend: true,
    level: process.env.ENV === 'development' ? 'debug' : 'info'
  });
 
  var logger = new (winston.Logger)({
    transports: [
      transport
    ]
  });
 
  logger.info('Hello World!');

The DailyRotateFile transport can rotate files by minute, hour, day, month, year or weekday. In addition to the options accepted by the File transport, the Daily Rotate File Transport also accepts the following options:

  • datePattern: A string representing the pattern to be used when appending the date to the filename (default 'yyyy-MM-dd'). The meta characters used in this string will dictate the frequency of the file rotation. For example, if your datePattern is simply 'HH' you will end up with 24 log files that are picked up and appended to every day.
  • prepend: Defines if the rolling time of the log file should be prepended at the beginning of the filename (default 'false').
  • localTime: A boolean to define whether time stamps should be local (default 'false' means that UTC time will be used).
  • zippedArchive: A boolean to define whether or not to gzip archived log files (default 'false').
  • maxDays: A number representing the maximum number of days a log file will be saved. Any log file older than this specified number of days will be removed. If not value or a 0, no log files will be removed.
  • createTree: When combined with a datePattern that includes path delimiters, the transport will create the entire folder tree to the log file. Example: datePattern: '/yyyy/MM/dd.log', createTree: true will create the entire path to the log file prior to writing an entry.

Valid meta characters in the datePattern are:

  • yy: Last two digits of the year.
  • yyyy: Full year.
  • M: The month.
  • MM: The zero padded month.
  • d: The day.
  • dd: The zero padded day.
  • H: The hour.
  • HH: The zero padded hour.
  • m: The minute.
  • mm: The zero padded minute.
  • ddd: The weekday (Mon, Tue, ..., Sun).

Metadata: Logged via util.inspect(meta);

LICENSE

MIT

AUTHOR: Charlie Robbins
MAINTAINER: Matt Berther