首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >node log4js maxlogsize不起作用

node log4js maxlogsize不起作用
EN

Stack Overflow用户
提问于 2017-01-19 16:21:08
回答 1查看 1K关注 0票数 0

我尝试获取小于20mb的重写日志文件。我已经将我的log4js文件附加器的最大日志大小参数配置为20mb,但它不起作用。记录器写入大于20mb的日志文件。那么,可能有人知道如何解决这个问题?

代码语言:javascript
复制
"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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-19 20:29:51

固定附加器:

代码语言:javascript
复制
{
        type: "file",
        filename: __dirname + '/../data/' + "/smartHomeServer.log",
        maxLogSize: 20971520,
        backups: 1,
        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];
                        });
                    }
                }
            }
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41736982

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档