forked from maratonusp/contestwatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
53 lines (46 loc) · 1.25 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
const winston = require('winston');
const dateFormat = require('dateformat');
/**
* logger.info("message");
* logger.warn("message");
* logger.error("message");
* You can use metadata too
* logger.info("message", {foo: bar});
*
* For more details: https://github.com/winstonjs/winston/tree/2.x
*/
function getDate() {
return dateFormat(new Date(), "UTC:[dd/mm/yy HH:MM]");
}
function getFormatter(options) {
date = getDate();
level = options.level.toUpperCase();
if (options.colorize)
level = winston.config.colorize(options.level, level)
return date + ' ' + level + ': ' +
(options.message ? options.message : '') +
(options.meta && Object.keys(options.meta).length ? '\n'+ JSON.stringify(options.meta) : '');
}
winston.remove(winston.transports.Console);
winston.add(winston.transports.Console, {
level: 'debug',
json: false,
colorize: true,
formatter: getFormatter,
handleExceptions: true,
humanReadableUnhandledException: true
});
winston.add(winston.transports.File, {
level: 'debug',
filename: './run.log',
json: false,
colorize: false,
formatter: getFormatter,
maxsize: 100000, // 100 KB
maxFiles: 5,
tailable: true,
zippedArchive: true,
handleExceptions: true,
humanReadableUnhandledException: true
});
module.exports = winston;