我看到日志以最高编号旋转为最新日志 -
log15.log - 最新的
log14.log
log13.log
如何切换订单以便log.log成为最新的?
var ProxyLogger = function (level,logsPath) {
console.log("using log level: " + level);
this.level = level;
this.logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({'maxsize': 128 * 1024, 'maxFiles': 10,
'timestamp': function() { var d = new Date();
return d.getDate() +"-" + (d.getMonth()+1) + "-" + d.getFullYear() +" " + d.getHours() +":" + d.getMinutes() +":" + d.getSeconds() + " " + d.getMilliseconds();}
, filename: logsPath + '/proxy.log', level: level, 'json': false}),
new (winston.transports.Console)({level: level, 'timestamp': function() { var d = new Date();
return d.getDate() +"-" + (d.getMonth()+1) + "-" + d.getFullYear() +" " + d.getHours() +":" + d.getMinutes() +":" + d.getSeconds() + " " + d.getMilliseconds();
}})
]
});
};
由于
答案 0 :(得分:0)
从你的问题中不清楚log15.log等是什么,但我可以给出两种不同场景的答案。
如果log#.log只是打印输出,你可以将它们推送到一个数组,然后在完成任务时,向后迭代数组并记录每次迭代,如下所示:
var logs = []
function(logmessage){ //some log generating loop
logs.push(logmessage)
}
for(var i = log.length-1; i>0; i--){
console.log(logs[i])
}
或者如果log#.log是文件,您可以使用以下命令在每次迭代时手动设置其名称:
winston.add(winston.transports.File, { filename: 'log#.log', level: 'level' });
希望有所帮助!