forked from gropox/randomblockchain
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.js
52 lines (42 loc) · 1.39 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
var global = require("./global");
var debug = require("debug");
let Logger = function(source, level) {
console.log("construct logger for " + source);
let p = source.split(/[\/\\]/);
this.s = p[p.length-1].split(".")[0];
this._trc = debug("randomblockchain:trc:" + this.s);
this._dbg = debug("randomblockchain:dbg:" + this.s);
this._inf = debug("randomblockchain:inf:" + this.s);
this._wrn = debug("randomblockchain:wrn:" + this.s);
this._err = debug("randomblockchain:err:" + this.s);
if(typeof process.env.DEBUG == "undefined") {
let dbgNamespace = "randomblockchain:err* randomblockchain:wrn* randomblockchain:inf*";
if(global.runtime.dl>0) {
dbgNamespace = dbgNamespace + " randomblockchain:dbg*";
}
if(global.runtime.dl>1) {
dbgNamespace = dbgNamespace + " randomblockchain:trc*";
}
console.log("enable " + dbgNamespace);
debug.enable(dbgNamespace);
}
this.trace = function(msg) {
this._trc(msg);
}
this.debug = function(msg) {
this._dbg(msg);
}
this.info = function(msg) {
this._inf(msg);
}
this.warn = function(msg) {
this._wrn(msg);
}
this.error = function(msg) {
this._err(msg);
}
}
new Logger("f",0);
module.exports.getLogger = function (f,l) {
return new Logger(f,l);
}