forked from maxtaco/node-framed-msgpack-rpc
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog.js
More file actions
132 lines (110 loc) · 2.8 KB
/
log.js
File metadata and controls
132 lines (110 loc) · 2.8 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Generated by IcedCoffeeScript 108.0.12
(function() {
var L, Logger, default_level, default_logger_class, stringify, util;
util = require('util');
exports.levels = L = {
NONE: 0,
DEBUG: 1,
INFO: 2,
WARN: 3,
ERROR: 4,
FATAL: 5,
TOP: 6
};
default_level = L.INFO;
stringify = function(o) {
if (o == null) {
return "";
} else if (o instanceof Uint8Array) {
return new TextDecoder().decode(o);
} else if (util.isError(o)) {
return o.toString();
} else {
return "" + o;
}
};
exports.Logger = Logger = (function() {
function Logger(_arg) {
this.prefix = _arg.prefix, this.remote = _arg.remote, this.level = _arg.level;
if (!this.prefix) {
this.prefix = "RPC";
}
if (!this.remote) {
this.remote = "-";
}
this.output_hook = function(m) {
return console.log(m);
};
this.level = this.level != null ? this.level : default_level;
}
Logger.prototype.set_level = function(l) {
return this.level = l;
};
Logger.prototype.set_remote = function(r) {
return this.remote = r;
};
Logger.prototype.set_prefix = function(p) {
return this.prefix = p;
};
Logger.prototype.debug = function(m) {
if (this.level <= L.DEBUG) {
return this._log(m, "D", null, L.DEBUG);
}
};
Logger.prototype.info = function(m) {
if (this.level <= L.INFO) {
return this._log(m, "I", null, L.INFO);
}
};
Logger.prototype.warn = function(m) {
if (this.level <= L.WARN) {
return this._log(m, "W", null, L.WARN);
}
};
Logger.prototype.error = function(m) {
if (this.level <= L.ERROR) {
return this._log(m, "E", null, L.ERROR);
}
};
Logger.prototype.fatal = function(m) {
if (this.level <= L.FATAL) {
return this._log(m, "F", null, L.FATAL);
}
};
Logger.prototype._log = function(m, l, ohook, level) {
var parts;
parts = [];
if (this.prefix != null) {
parts.push(this.prefix);
}
if (l) {
parts.push("[" + l + "]");
}
if (this.remote) {
parts.push(this.remote);
}
parts.push(stringify(m));
if (!ohook) {
ohook = this.output_hook;
}
return ohook(parts.join(" "), level);
};
Logger.prototype.make_child = function(d) {
return new Logger(d);
};
return Logger;
})();
default_logger_class = Logger;
exports.set_default_level = function(l) {
return default_level = l;
};
exports.set_default_logger_class = function(k) {
return default_logger_class = k;
};
exports.new_default_logger = function(d) {
if (d == null) {
d = {};
}
return new default_logger_class(d);
};
}).call(this);