-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
67 lines (66 loc) · 2.68 KB
/
logger.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
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
67
/**
* Logger | Bunyan
*/
const bunyan = require('bunyan')
const path = require('path');
const config = require('./config');
module.exports = () => {
function reqSerializer(req) {
return {
method: req.method,
url: req.url,
headers: req.headers,
};
}
const logger = bunyan.createLogger({
name: config.name,
src: true,
streams: [{
type: 'rotating-file',
level: 'info', // loging level
path: config.env === 'development' ? path.resolve(__dirname, 'log/development-info.log') : path.resolve(__dirname, 'log/production-info.log'),
period: '1d', // daily rotation
count: 3, // keep 3 back copies
},
{
type: 'rotating-file',
level: 'fatal', // loging level
path: config.env === 'development' ? path.resolve(__dirname, 'log/development-fatal.log') : path.resolve(__dirname, 'log/production-fatal.log'),
period: '1d', // daily rotation
count: 3, // keep 3 back copies
},
{
type: 'rotating-file',
level: 'error', // loging level
path: config.env === 'development' ? path.resolve(__dirname, 'log/development-error.log') : path.resolve(__dirname, 'log/production-error.log'),
period: '1d', // daily rotation
count: 3, // keep 3 back copies
},
{
type: 'rotating-file',
level: 'warn', // loging level
path: config.env === 'development' ? path.resolve(__dirname, 'log/development-warn.log') : path.resolve(__dirname, 'log/production-warn.log'),
period: '1d', // daily rotation
count: 3, // keep 3 back copies
},
{
type: 'rotating-file',
level: 'debug', // loging level
path: config.env === 'development' ? path.resolve(__dirname, 'log/development-debug.log') : path.resolve(__dirname, 'log/production-debug.log'),
period: '1d', // daily rotation
count: 3, // keep 3 back copies
},
{
type: 'rotating-file',
level: 'trace', // loging level
path: config.env === 'development' ? path.resolve(__dirname, 'log/development-trace.log') : path.resolve(__dirname, 'log/production-trace.log'),
period: '1d', // daily rotation
count: 3, // keep 3 back copies
},
],
serializers: {
req: reqSerializer,
},
});
return logger;
};