forked from Schibsted-Tech-Polska/stp.phantom-renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
36 lines (34 loc) · 1.05 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
var logger,
colors = require('colors'),
dateFormat = require('dateformat');
logger = {
timestamp: "yyyy-mm-dd HH:MM:ss.l",
processInfo: null,
events: {
info: { color: 'green', event: 'info' },
warn: { color: 'yellow', event: 'warning' },
error: { color: 'red', event: 'error' }
},
info: function(message) {
logger.write("info", message);
},
error: function(message) {
logger.write("error", message);
},
warn: function(message) {
logger.write("warn", message);
},
write: function(type, message) {
var processInfoMsg = logger.processInfo ? ' - ' + logger.processInfo : '';
console.log(dateFormat( new Date(), this.timestamp) + processInfoMsg + ' - ' + this.events[type].event[this.events[type].color] + ': ' + message);
},
setProcessInfo: function(processInfo) {
logger.processInfo = processInfo;
}
};
exports.logger = {
setProcessInfo: logger.setProcessInfo,
info: logger.info,
error: logger.error,
warn: logger.warn
};