Transport for winston based on rotating-file-stream.
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]
});
With npm:
$ npm install --save winston-rotating-file
const { WinstonRotatingFile } = require("winston-rotating-file");
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.
Check index.d.ts
for what is exported in
TypeScript.
Requires Node.js v10.x.
The package is tested under all Node.js versions currently supported accordingly to Node.js Release.
Do not hesitate to report any bug or inconsistency @github.
If you find useful this package, please consider the opportunity to donate some satoshis to this bitcoin address: 12p1p5q7sK75tPyuesZmssiMYr4TKzpSCN