链接
简介
https://juejin.im/post/57b962af7db2a200542a0fb3
官方文档
https://log4js-node.github.io/log4js-node/terms.html
github
https://github.com/log4js-node/log4js-node
栗子
官方栗子
https://github.com/log4js-node/log4js-example
{
"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"
}
},
"categories": {
"default": {
"appenders": ["app", "errors"],
"level": "DEBUG"
},
"http": {
"appenders": ["access"],
"level": "DEBUG"
}
}
}
/**
* Initialise log4js first, so we don't miss any log messages
*/
var log4js = require('log4js');
log4js.configure('./config/log4js.json');
var log = log4js.getLogger("startup");
var log = log4js.getLogger("app");
项目中使用的栗子
https://www.cnblogs.com/duhuo/p/5176154.html
注意, 这个栗子是旧版本的log4js
{
"appenders": [{
"category": "console",
"type": "console"
},
{
"category": "log_info",
"type": "file",
"filename": "./logs/log_info/info.log",
"maxLogSize": 104857500,
"backups": 100
},
{
"category": "log_stat",
"type": "datefile",
"filename": "./logs/log_stat/stat"
},
{
"category": "log_trace",
"type": "datefile",
"filename": "./logs/log_trace/trace"
},
{
"category": "log_error",
"type": "datefile",
"filename": "./logs/log_error/error"
},
{
"category": "log_todo",
"type": "datefile",
"filename": "./logs/log_todo/todo"
}
],
"replaceConsole": true,
"levels": {
"log_info": "ALL",
"log_stat": "ALL",
"log_trace": "ALL",
"log_error": "ALL",
"log_todo": "ALL"
}
}
概念
总览
https://www.jianshu.com/p/9604d08db899
level
category
log4js.getLogger(‘somecategory’)
得到的结果:
[2016-08-21 01:16:00.212] [DEBUG] somecategory - Time: 2016-08-20T17:16:00.212Z
Appender
文档
https://log4js-node.github.io/log4js-node/appenders.html
使用邮件
https://github.com/log4js-node/smtp