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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
let log4js = require('log4js');
let path = require('path');
let fs = require('fs');
let basePath = path.join(__dirname, '/logs/');
let defaultPath = path.join(basePath, '/default_database/');
let writeDbPath = path.join(basePath, '/write_database/');
let readDbPath = path.join(basePath, '/read_database/');
let confirmPath = function (pathStr) {
console.log("pathStr",pathStr);
if (!fs.existsSync(pathStr)) {
fs.mkdirSync(pathStr);
console.log('createPath: ' + pathStr);
}
};
//创建log的根目录'logs'
if (basePath) {
confirmPath(basePath);
//根据不同的logType创建不同的文件目录
confirmPath(defaultPath);
confirmPath(writeDbPath);
confirmPath(readDbPath);
}
log4js.configure({
appenders: {
out: {type: 'console'},
default: {
type: 'dateFile',
filename: defaultPath,
"pattern": "yyyy-MM-dd-hh.log",
alwaysIncludePattern: true
},
write_db: {
type: 'dateFile',
filename: writeDbPath,
"pattern": "yyyy-MM-dd-hh.log",
alwaysIncludePattern: true
},
read_db: {
type: 'dateFile',
filename: readDbPath,
"pattern": "yyyy-MM-dd-hh.log",
alwaysIncludePattern: true
}
},
categories: {
default: {
appenders: ['default'],
level: 'info'
},
write_db: {
appenders: ['write_db'],
level: 'info'
},
read_db: {
appenders: ['read_db'],
level: 'info'
}
},
replaceConsole: true //是否替换console.log
});
module.exports = log4js;
|