-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlogUtils.js
58 lines (53 loc) · 1.65 KB
/
logUtils.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
`use strict`
const { createLogger, format, transports } = require('winston');
const { combine, printf, timestamp, splat, align} = format;
const fileSys = require('fs');
const Yaml = require('js-yaml');
//Pull in configuration options - setup.yml
let config;
try {
config = Yaml.load(fileSys.readFileSync('setup.yml'))
} catch (error) {
//Dies hard this way.. This is a major issue we just fail outright on
console.log(`Error in log.js: ${error}`)
process.exit(-1);
}
//Setup the Logger
const logs = createLogger({
level: config.logging.logLevel,
transports: [
new transports.File({
filename: config.logging.logPath,
maxsize: config.logging.maxSize,
maxFiles: config.logging.maxFiles,
colorize: true,
format: combine(
splat(),
timestamp(),
align(),
printf((info) => {
const { timestamp, level, message, ...args} = info;
const ts = timestamp.slice(0, 19).replace('T', ' ');
return `${ts} [${level}]: ${message} ${Object.keys(args).length ? JSON.stringify(args, null, 2) : ''}`;
}),
)
}),
new (transports.Console)({
format: format.combine(
format.colorize({
all:true
}),
splat(),
timestamp(),
align(),
printf((info) => {
const { timestamp, level, message, ...args} = info;
const ts = timestamp.slice(0, 19).replace('T', ' ');
return `${ts} [${level}]: ${message} ${Object.keys(args).length ? JSON.stringify(args, null, 2) : ''}`;
}),
)
})
],
exitOnError: false, // do not exit on handled exceptions
});
module.exports = logs;