-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathlog4js.js
39 lines (35 loc) · 1.03 KB
/
log4js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var log4js = require('log4js');
log4js.configure({
//控制台输出
appenders: [
{ type: 'console' },{
type: 'dateFile',
filename: 'logs/app.log',
maxLogSize: 1024,
backups:4,
category: 'normal'
},
{
type: "dateFile",
filename: 'logs/app.log',
pattern: "-yyyy-MM-dd",
alwaysIncludePattern: false,
maxLogSize: 1024*1024
// category: 'normal'
}//日期文件格式
],
replaceConsole: true, //替换console.log
// levels: {
// dateFileLog: 'INFO'
// }
});
exports.getLogger = function (name) {
var logger = log4js.getLogger(name);
logger.setLevel('INFO');
return logger;
}
exports.use = function (app, logger) {
//页面请求日志,用auto的话,默认级别是WARN
//app.use(log4js.connectLogger(dateFileLog, {level:'auto', format:':method :url'}));
app.use(log4js.connectLogger(logger, {level: 'info', format: ':method :url'}));
}