我尝试让重写的日志文件小于 20mb。我已将我的 log4js 文件附加程序配置为 maxlogsize 参数为 20mb,但它不起作用。记录器写入大于 20mb 的日志文件。那么可能有人知道如何解决这个问题?
"use strict";
let path = require("path");
let log4js = require('log4js');
let $depth = 10;
log4js.configure({
appenders: [
{
type: "console",
layout: {
type : "pattern",
pattern : "[%d{ISO8601}] %[%p {%x{ln}} -%]\t%m",
tokens: {
ln : function() {
var errorStack = (new Error).stack.split("\n");
var tempLocation = errorStack[$depth];
if ( typeof tempLocation !== 'undefined' && tempLocation ) {
return tempLocation .replace(/^\s+at\s+(\S+)\s\((.+?)([^\/]+):(\d+):\d+\)$/, function (){
return arguments[1] +' '+ arguments[3] +' line '+ arguments[4];
});
}
}
}
}
},
{
type: "file",
filename: __dirname + '/../data/' + "/smartHomeServer.log",
layout: {
type : "pattern",
pattern : "[%d{ISO8601}] %[%p {%x{ln}} -%]\t%m",
maxLogSize: 20971520,
backups: 1,
tokens: {
ln : function() {
var errorStack = (new Error).stack.split("\n");
var tempLocation = errorStack[$depth];
if ( typeof tempLocation !== 'undefined' && tempLocation ) {
return tempLocation.replace(/^\s+at\s+(\S+)\s\((.+?)([^\/]+):(\d+):\d+\)$/, function () {
return arguments[1] + ' ' + arguments[3] + ' line ' + arguments[4];
});
}
}
}
}
}
]
});
let log = log4js.getLogger();
module.exports = log;