forked from barbatus/meteor-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.js
62 lines (48 loc) · 1.22 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
52
53
54
55
56
57
58
59
60
61
62
var util = require("util");
function Logger() {
this.prefix = "[meteor-typescript]: ";
this.llevel = process.env.TYPESCRIPT_LOG;
}
var LP = Logger.prototype;
LP.debug = function(format, ...args) {
if (this.isDebug()) {
var msg = args.length ? util.format(format, ...args) : format;
console.log(this.prefix + msg);
}
};
LP.assert = function(format, ...args) {
if (this.isAssert()) {
var msg = args.length ? util.format(format, ...args) : format;
console.log(this.prefix + msg);
}
};
LP.isDebug = function() {
return this.llevel >= 2;
};
LP.isProfile = function() {
return this.llevel >= 3;
};
LP.isAssert = function() {
return this.llevel >= 4;
};
LP.newProfiler = function(name) {
var fullName = util.format("%s%s", this.prefix, name);
var profiler = new Profiler(fullName);
if (this.isProfile()) profiler.start();
return profiler;
};
function Profiler(name) {
this.name = name;
}
var PP = Profiler.prototype;
PP.start = function() {
console.log("%s started", this.name);
console.time(util.format("%s time", this.name));
this._started = true;
};
PP.end = function() {
if (this._started) {
console.timeEnd(util.format("%s time", this.name));
}
};
export default new Logger();