日志管理log4js的配置

以前就是在app.js 直接用,今天把它抽出来了。

log4js.json

{
    "appenders":
    [
        {
            "type":"console",
            "category":"console"
        },
        {
            "category":"log_file",
            "type": "file",
            "filename": "./logs/log_file/file.log",
            "maxLogSize": 104800,
            "backups": 100,
            "category": "normal"
        },
        {
            "category":"log_date",
            "type": "dateFile",
            "filename": "./logs/log_date/date",
            "alwaysIncludePattern": true,
            "pattern": "-yyyy-MM-dd-hh.log",
            "category": "normal"

        }
    ],
    "replaceConsole": true
}

使用:

var log4js_config = require("./config/log4js.json");
log4js.configure(log4js_config);
var logger = log4js.getLogger('normal');
logger.setLevel('INFO');
app.use(log4js.connectLogger(logger, {level:log4js.levels.INFO}));

  

posted @ 2016-09-18 18:42  快乐~  阅读(5864)  评论(0编辑  收藏  举报