node-log4js3.0.6配置
const log4js = require('log4js');
const conf = {
"appenders": {
"access": {
"type": "dateFile",
"filename": "log/access.log",
"pattern": "-yyyy-MM-dd",
"category": "http"
},
"app": {
"type": "file",
"filename": "log/app.log",
"maxLogSize": 10485760,
"numBackups": 3
},
"errorFile": {
"type": "file",
"filename": "log/errors.log"
},
"errors": {
"type": "logLevelFilter",
"level": "ERROR",
"appender": "errorFile"
},
console: { type: 'console' } //设置窗口打印显示,方面开发环境的调试
},
"categories": {
"default": { "appenders": ['console', "app", "errors"], "level": "all" },
"http": { "appenders": [ "access"], "level": "DEBUG" }
}
};
log4js.configure(conf);
上面的设置,cmd窗口打印显示,只打印app,errors的log
如果只打印app的log,则单独设置app如下;
"categories": {
"default": { "appenders": [ "errors"], "level": "all" },
"http": { "appenders": [ "access"], "level": "DEBUG" } ,
"app": { "appenders": ['console',"app"], "level": "DEBUG" }
}
作者:绿茶叶
出处:http://www.cnblogs.com/greenteaone/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号