日志管理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}));