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" } 
}

猜你喜欢

转载自www.cnblogs.com/greenteaone/p/10076161.html