-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.js
49 lines (41 loc) · 1.11 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
'use strict';
/*
* Copyright (C) 2017 Topcoder Inc., All Rights Reserved.
*/
/**
* This module contains the winston logger configuration.
*/
const winston = require('winston');
const config = require('config');
const chalk = require('chalk');
const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
level: config.logLevel,
timestamp: () => new Date().toISOString(),
formatter(options) {
const message = options.message || '';
let meta = '';
if (options.meta && Object.keys(options.meta).length) {
meta = '\n\t' + JSON.stringify(options.meta);
}
let level = options.level.toUpperCase();
switch (level) {
case 'INFO':
level = chalk.cyan(level);
break;
case 'WARN':
level = chalk.yellow(level);
break;
case 'ERROR':
level = chalk.red(level);
break;
default:
break;
}
return `[${options.timestamp()}][${level}] ${message} ${meta}`;
}
})
]
});
module.exports = logger;