GithubHelp home page GithubHelp logo

isabella232 / winston-daily-rotate-file Goto Github PK

View Code? Open in Web Editor NEW

This project forked from winstonjs/winston-daily-rotate-file

0.0 0.0 0.0 558 KB

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

License: MIT License

JavaScript 100.00%

winston-daily-rotate-file's Introduction

winston-daily-rotate-file

NPM version Build Status Dependency Status

NPM

A transport for winston which logs to a rotating file. Logs can be rotated based on a date, size limit, and old logs can be removed based on count or elapsed days.

Starting with version 2.0.0, the transport has been refactored to leverage the the file-stream-rotator module. Some of the options in the 1.x versions of the transport have changed. Please review the options below to identify any changes needed.

Compatibility

Please note that if you are using winston@2, you will need to use winston-daily-rotate-file@3. winston-daily-rotate-file@4 removed support for winston@2.

Install

npm install winston-daily-rotate-file

Options

The DailyRotateFile transport can rotate files by minute, hour, day, month, year or weekday. In addition to the options accepted by the logger, winston-daily-rotate-file also accepts the following options:

  • frequency: A string representing the frequency of rotation. This is useful if you want to have timed rotations, as opposed to rotations that happen at specific moments in time. Valid values are '#m' or '#h' (e.g., '5m' or '3h'). Leaving this null relies on datePattern for the rotation times. (default: null)
  • datePattern: A string representing the moment.js date format to be used for rotating. 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. (default: 'YYYY-MM-DD')
  • zippedArchive: A boolean to define whether or not to gzip archived log files. (default: 'false')
  • filename: Filename to be used to log to. This filename can include the %DATE% placeholder which will include the formatted datePattern at that point in the filename. (default: 'winston.log.%DATE%')
  • dirname: The directory name to save log files to. (default: '.')
  • stream: Write directly to a custom stream and bypass the rotation capabilities. (default: null)
  • maxSize: Maximum size of the file after which it will rotate. This can be a number of bytes, or units of kb, mb, and gb. If using the units, add 'k', 'm', or 'g' as the suffix. The units need to directly follow the number. (default: null)
  • maxFiles: Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null)
  • options: An object resembling https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options indicating additional options that should be passed to the file stream. (default: { flags: 'a' })
  • auditFile: A string representing the name of the audit file. This can be used to override the default filename which is generated by computing a hash of the options object. (default: '..json')
  • utc: Use UTC time for date in filename. (default: false)
  • extension: File extension to be appended to the filename. (default: '')
  • createSymlink: Create a tailable symlink to the current active log file. (default: false)
  • symlinkName: The name of the tailable symlink. (default: 'current.log')

Usage

  var winston = require('winston');
  require('winston-daily-rotate-file');

  var transport = new winston.transports.DailyRotateFile({
    filename: 'application-%DATE%.log',
    datePattern: 'YYYY-MM-DD-HH',
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d'
  });

  transport.on('rotate', function(oldFilename, newFilename) {
    // do something fun
  });

  var logger = winston.createLogger({
    transports: [
      transport
    ]
  });

  logger.info('Hello World!');

ES6

import  *  as  winston  from  'winston';
import  'winston-daily-rotate-file';


const transport = new winston.transports.DailyRotateFile({
  filename: 'application-%DATE%.log',
  datePattern: 'YYYY-MM-DD-HH',
  zippedArchive: true,
  maxSize: '20m',
  maxFiles: '14d'
});

transport.on('rotate', function(oldFilename, newFilename) {
  // do something fun
});

const logger = winston.createLogger({
  transports: [
    transport
  ]
});

logger.info('Hello World!');

Typescript

import  *  as  winston  from  'winston';
import  DailyRotateFile from 'winston-daily-rotate-file';

const transport: DailyRotateFile = new DailyRotateFile({
    filename: 'application-%DATE%.log',
    datePattern: 'YYYY-MM-DD-HH',
    zippedArchive: true,
    maxSize: '20m',
    maxFiles: '14d'
  });

transport.on('rotate', function(oldFilename, newFilename) {
      // do something fun
    });

const logger = winston.createLogger({
transports: [
  transport
]});

logger.info('Hello World!');

This transport emits the following custom events:

  • new: fired when a new log file is created. This event will pass one parameter to the callback (newFilename).
  • rotate: fired when the log file is rotated. This event will pass two parameters to the callback (oldFilename, newFilename).
  • archive: fired when the log file is archived. This event will pass one parameter to the callback (zipFilename).
  • logRemoved: fired when a log file is removed from the file system. This event will pass one parameter to the callback (removedFilename).

LICENSE

MIT

MAINTAINER: Matt Berther

winston-daily-rotate-file's People

Contributors

afmeirelles avatar amcereijo avatar apollon77 avatar bruceauyeung avatar brunolemos avatar cbeliveau avatar dependabot[bot] avatar dplewis avatar dreamerkumar avatar fdasfsafsa avatar garcia556 avatar ifree92 avatar iliyazelenko avatar indexzero avatar kanna727 avatar krayzeekev avatar lacivert avatar maharjanraj avatar markjbyrne81 avatar mattberther avatar mehdibeldjilali avatar mtreerungroj avatar nyuno avatar oseau avatar pataiadam avatar perrin4869 avatar shashankpaytm avatar slessi avatar troylatchman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.