This repository has been archived by the owner on Jan 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.js
70 lines (64 loc) · 1.61 KB
/
log.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
//Setup logging
var winston = require('winston');
var logger = new winston.Logger({
levels: {
fatal: 4,
error: 3,
info: 2,
warn: 1,
debug: 0
}
});
winston.config.addColors({
fatal: 'blue',
error: 'red',
info: 'green',
warn: 'yellow',
debug: 'grey'
});
//Output Log debug messages to console, when in development mode
if (!process.env.NODE_ENV ||
(process.env.NODE_ENV === 'development')) {
logger.add(winston.transports.Console, { level: 'debug' });
logger.transports.console.colorize = true;
}
var id = 0;
var log = function (module, level, uuid, message, metadata) {
logger.log(level, JSON.stringify({
id: id,
timestamp: new Date(),
module: module,
uuid: uuid,
level: level,
message: message,
metadata: metadata
}));
id += 1;
};
module.exports = {
add: function (transport, options) {
logger.add(transport, options);
},
remove: function (transport) {
logger.remove(transport);
},
getLogger: function (options) {
return {
fatal: function (uuid, message, metadata) {
log(options.module, 'fatal', uuid, message, metadata);
},
error: function (uuid, message, metadata) {
log(options.module, 'error', uuid, message, metadata);
},
info: function (uuid, message, metadata) {
log(options.module, 'info', uuid, message, metadata);
},
warn: function (uuid, message, metadata) {
log(options.module, 'warn', uuid, message, metadata);
},
debug: function (uuid, message, metadata) {
log(options.module, 'debug', uuid, message, metadata);
}
};
}
};