-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (46 loc) · 1.88 KB
/
index.js
File metadata and controls
62 lines (46 loc) · 1.88 KB
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
function LogPlugin () {
this.fileLogger = {};
this.msgLogger = {};
this.level = {};
}
function isEmpty (obj) { return Object.keys(obj).length == 0; }
LogPlugin.prototype.sendMsg = function(msg){
if (typeof(msg) == 'string') {
var stack = '';
this.msgLogger.addLogEntry(this.level, msg, stack).catch(function(error) {
this.fileLogger.error(error);
}); }
if (typeof(msg) == 'object') {
this.msgLogger.addLogEntry(this.level, msg.message, msg.stack).catch(function(error) {
this.fileLogger.error(error);
}); }
};
LogPlugin.prototype.fatal = function(msg) {
if (!isEmpty(this.fileLogger)) {
this.fileLogger.fatal(msg); }
if (!isEmpty(this.msgLogger) && this.level <= this.logLevels.fatal) {
this.sendMsg(msg); } };
LogPlugin.prototype.error = function(msg) {
if (!isEmpty(this.fileLogger)) {
console.log(msg);
this.fileLogger.error(msg); }
if (!isEmpty(this.msgLogger) && this.level <= this.logLevels.error) {
this.sendMsg(msg); } };
LogPlugin.prototype.info = function(msg) {
if (!isEmpty(this.fileLogger)) {
this.fileLogger.info(msg); }
if (!isEmpty(this.msgLogger) && this.level <= this.logLevels.info) {
this.sendMsg(msg); } };
LogPlugin.prototype.debug = function(msg) {
if (!isEmpty(this.fileLogger)) {
console.log(msg);
this.fileLogger.debug(msg); }
if (!isEmpty(this.msgLogger) && this.level <= this.logLevels.debug) {
this.sendMsg(msg); } };
LogPlugin.prototype.setFileLogger = function(bunyanLogger) {
this.fileLogger = bunyanLogger; };
LogPlugin.prototype.setMsgLogger = function(wascallyClient, level) {
this.msgLogger = wascallyClient;
this.level = level; };
LogPlugin.prototype.logLevels = { fatal: 60, error: 50, warn: 40, info: 30, debug: 20, trace: 10 };
module.exports = new LogPlugin();