winston-rotating-file
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

winston-rotating-file

Build Status Code Climate Test Coverage Donate

NPM version Types NPM downloads

Dependencies Dev Dependencies Dependents

Description

Transport for winston based on rotating-file-stream.

Usage

const { WinstonRotatingFile } = require("winston-rotating-file");
const winston = require("winston");
 
const logger = winston.createLogger({
  format: winston.format.combine(
    winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
    winston.format.printf(info => `${info.timestamp} ${info.message}\n`)
  ),
  transports: [
    new WinstonRotatingFile({
      filename: "file.log",
      rfsOptions: {
        size: "10M", // rotate every 10 MegaBytes written
        interval: "1d", // rotate daily
        compress: "gzip" // compress rotated files
      }
    })
  ]
});

or (if access to rotating-file-stream events is required)

const { WinstonRotatingFile } = require("winston-rotating-file");
const winston = require("winston");
 
const transport = new WinstonRotatingFile({
  filename: "file.log",
  rfsOptions: {
    size: "10M", // rotate every 10 MegaBytes written
    interval: "1d", // rotate daily
    compress: "gzip" // compress rotated files
  }
});
 
transport.stream.on("rotated", filename => {});
 
const logger = winston.createLogger({
  format: winston.format.combine(
    winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
    winston.format.printf(info => `${info.timestamp} ${info.message}\n`)
  ),
  transports: [transport]
});

Installation

With npm:

$ npm install --save winston-rotating-file

API

const { WinstonRotatingFile } = require("winston-rotating-file");

new WinstonRotatingFile(options)

Creates the Transport for winston. Accepts all options for winston-transport (please refer to winston for details) plus following specific options:

  • filename (required)
  • rfsOptions

both of them passed to rfs.createStream, please refer to rotating-file-stream for detailed options description.

TypeScript

Check index.d.ts for what is exported in TypeScript.

Compatibility

Requires Node.js v10.x.

The package is tested under all Node.js versions currently supported accordingly to Node.js Release.

Licence

MIT Licence

Bugs

Do not hesitate to report any bug or inconsistency @github.

Donating

If you find useful this package, please consider the opportunity to donate some satoshis to this bitcoin address: 12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN

Package Sidebar

Install

npm i winston-rotating-file

Weekly Downloads

25

Version

0.2.0

License

MIT

Unpacked Size

8.95 kB

Total Files

5

Last publish

Collaborators

  • cicci