-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
104 lines (99 loc) · 3.97 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var fs = require('fs');
var bunyan = require('bunyan');
var bunyanDebugStream = require('bunyan-debug-stream');
var bunyanPretty = require('bunyan-pretty');
var PrettyStream = require('bunyan-prettystream');
var prettyStdOut = new PrettyStream();
prettyStdOut.pipe(process.stdout);
var RotatingFileStream = require('bunyan-rotating-file-stream')
var logDir = process.env.OPENSHIFT_LOG_DIR || process.env.VIADUCT_LOGS_DIR || 'logs'
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
var logger = bunyan.createLogger(
{
src: true,
name: 'logger',
streams: [
{
level: 'trace',
stream: new RotatingFileStream({
path: logDir + '/log_trace.txt',
period: '30d', // hourly rotation
threshold: '20m', // Rotate log files larger than 10 megabytes
rotateExisting: true, // Give ourselves a clean file when we start up, based on period
totalSize: '40m', // Don't keep more than 20mb of archived log files }
totalFiles: 2,
gzip: true // Compress the archive log files to save space
}),
},
{
level: 'trace',
stream: prettyStdOut,
},
{
level: 'debug',
stream: new RotatingFileStream({
path: logDir + '/log_debug.txt',
period: '30d', // daily rotation
threshold: '20m', // Rotate log files larger than 10 megabytes
rotateExisting: true, // Give ourselves a clean file when we start up, based on period
totalSize: '40m', // Don't keep more than 20mb of archived log files
totalFiles: 2,
gzip: true // Compress the archive log files to save space
})
},
{
level: 'info',
stream: new RotatingFileStream({
path: logDir + '/log_info.txt',
period: '30d', // daily rotation
threshold: '20m', // Rotate log files larger than 10 megabytes
rotateExisting: true, // Give ourselves a clean file when we start up, based on period
totalSize: '40m', // Don't keep more than 20mb of archived log files
totalFiles: 3,
gzip: true // Compress the archive log files to save space
})
},
{
level: 'warn',
stream: new RotatingFileStream({
level: 'warn',
path: logDir + '/log_warn.txt',
period: '30d', // daily rotation
threshold: '20m', // Rotate log files larger than 10 megabytes
rotateExisting: true, // Give ourselves a clean file when we start up, based on period
totalSize: '40m', // Don't keep more than 20mb of archived log files
totalFiles: 3,
gzip: true // Compress the archive log files to save space
})
},
{
level: 'error',
stream: new RotatingFileStream({
path: logDir + '/log_error.txt',
period: '30d', // daily rotation
threshold: '20m', // Rotate log files larger than 10 megabytes
rotateExisting: true, // Give ourselves a clean file when we start up, based on period
totalSize: '40m', // Don't keep more than 20mb of archived log files
totalFiles: 3,
gzip: true // Compress the archive log files to save space
})
},
{
level: 'fatal',
stream: new RotatingFileStream({
path: logDir + '/log_fatal.txt',
period: '30d', // daily rotation
threshold: '20m', // Rotate log files larger than 10 megabytes
rotateExisting: true, // Give ourselves a clean file when we start up, based on period
totalSize: '40m', // Don't keep more than 20mb of archived log files
totalFiles: 3,
gzip: true // Compress the archive log files to save space
})
},
],
serializers: bunyanDebugStream.serializers,
}
);
module.exports = logger