我有将事件记录到logs/server.log
的winston logger,当它旋转文件时,由于日期格式,它创建了server20170321114031.log
,但是我想以这种格式旋转文件server.log.20170321114031
,并且当前记录文件名应始终为server.log
有可能实现使用Winston吗?
winston.js
logger = new (winston.Logger)({
level: null,
transports: [
// new (winston.transports.Console)(),
new (winston.transports.File)({
filename: './logs/server.log',
maxsize: 1024 * 1024 * 20,//15728640 is 15 MB
timestamp: false,
json: false,
rotationFormat: function() {
return getFormattedDate();
function getFormattedDate() {
var temp = new Date();
return dateStr = padStr(temp.getFullYear()) +
padStr(1 + temp.getMonth()) +
padStr(temp.getDate()) +
padStr(temp.getHours()) +
padStr(temp.getMinutes()) +
padStr(temp.getSeconds());
}
function padStr(i) {
return (i < 10) ? "0" + i : "" + i;
}
},
formatter: function (options) {
return options.message;
}
})
]
});
最佳答案
见https://github.com/winstonjs/winston/pull/205
logger.configure({
category1: {
dailyRotateFile: {
colorize: 'true',
filename: 'dailyRotateFile.log',
datePattern: '.yyyy-MM-dd',
maxsize: 20000
}
}
});
关于javascript - 如何使用Winston记录器最后附加日期和时间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42936730/