winston-rotating-file
v0.2.0
Published
Transport for winston based on rotating-file-stream
Downloads
149
Readme
winston-rotating-file
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
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