温斯顿每日旋转文件 maxSize 不起作用
Winston daily rotate file maxSize is not working
代码如下。使用 winston daily rotate file 未创建新文件
当达到 maxSize 即 2 mb 时,不会创建新文件。可能是什么问题呢?这是我的配置有问题的错误吗?我尝试添加删除扩展名或更改文件名,但它似乎不起作用
const customLevels = {
levels: {
debug: 3,
info: 2,
error: 1,
critical: 0,
},
filename: {
debug: path.join(
__dirname,
`../../logs/debug/%DATE%_debug`
),
info: path.join(
__dirname,
`../../logs/info/%DATE%_info`
),
error: path.join(
__dirname,
`../../logs/error/%DATE%_error`
),
critical: path.join(
__dirname,
`../../logs/critical/%DATE%_critical`
),
},
};
let logger = createLogger({
levels: customLevels.levels,
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss',
}),
format.simple()
),
transports: [
new transports.DailyRotateFile({
filename: customLevels.filename.debug,
maxsize: '2m',
extension: '.log',
level: 'debug',
}),
new transports.DailyRotateFile({
filename: customLevels.filename.info,
extension: '.log',
maxsize: '2m',
level: 'info',
}),
new transports.DailyRotateFile({
filename: customLevels.filename.error,
handleExceptions: true,
maxsize: '2m',
extension: '.log',
level: 'error',
}),
new transports.DailyRotateFile({
filename: customLevels.filename.critical,
handleExceptions: true,
extension: '.log',
maxsize: '2m',
level: 'critical',
}),
],
// exitOnError: false
});
您的代码具有键 maxsize
,而实际上它应该是 maxSize
。通常键和绑定名称是 JavaScript 中的驼峰式。您可以在 NPM 上看到这一点:
https://www.npmjs.com/package/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'
});
代码如下。使用 winston daily rotate file 未创建新文件 当达到 maxSize 即 2 mb 时,不会创建新文件。可能是什么问题呢?这是我的配置有问题的错误吗?我尝试添加删除扩展名或更改文件名,但它似乎不起作用
const customLevels = {
levels: {
debug: 3,
info: 2,
error: 1,
critical: 0,
},
filename: {
debug: path.join(
__dirname,
`../../logs/debug/%DATE%_debug`
),
info: path.join(
__dirname,
`../../logs/info/%DATE%_info`
),
error: path.join(
__dirname,
`../../logs/error/%DATE%_error`
),
critical: path.join(
__dirname,
`../../logs/critical/%DATE%_critical`
),
},
};
let logger = createLogger({
levels: customLevels.levels,
format: format.combine(
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss',
}),
format.simple()
),
transports: [
new transports.DailyRotateFile({
filename: customLevels.filename.debug,
maxsize: '2m',
extension: '.log',
level: 'debug',
}),
new transports.DailyRotateFile({
filename: customLevels.filename.info,
extension: '.log',
maxsize: '2m',
level: 'info',
}),
new transports.DailyRotateFile({
filename: customLevels.filename.error,
handleExceptions: true,
maxsize: '2m',
extension: '.log',
level: 'error',
}),
new transports.DailyRotateFile({
filename: customLevels.filename.critical,
handleExceptions: true,
extension: '.log',
maxsize: '2m',
level: 'critical',
}),
],
// exitOnError: false
});
您的代码具有键 maxsize
,而实际上它应该是 maxSize
。通常键和绑定名称是 JavaScript 中的驼峰式。您可以在 NPM 上看到这一点:
https://www.npmjs.com/package/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'
});