-
Notifications
You must be signed in to change notification settings - Fork 42
/
logger.js
74 lines (56 loc) · 1.5 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
63
64
65
66
67
68
69
70
71
72
73
74
const GLib = imports.gi.GLib;
var Logger = class Logger{
constructor(name, level){
this.base = name;
if (!level){
level = Logger.DEFAULT_LEVEL;
}
this.level = level;
}
checkLevel(level){
return level === undefined || this.level === undefined || level >= this.level;
}
log (name, message, level){
if (this.checkLevel(level)){
global.log("[" + name + "]" + this.base + " " + message);
}
}
debug (message){
this.log("DEBUG", message, Logger.LEVEL_DEBUG);
}
info (message){
this.log("INFO", message, Logger.LEVEL_INFO);
}
warn (message){
this.log("WARN", message, Logger.LEVEL_WARN);
}
error (message){
this.log("ERROR", message, Logger.LEVEL_ERROR);
}
getLogger (clazz){
return new Logger(this.base + "[" + clazz + "]", this.level);
}
is_debug (){
return this.checkLevel(Logger.LEVEL_DEBUG);
}
is_info (){
return this.checkLevel(Logger.LEVEL_INFO);
}
is_warn (){
return this.checkLevel(Logger.LEVEL_WARN);
}
is_error (){
return this.checkLevel(Logger.LEVEL_ERROR);
}
}
Logger.LEVEL_DEBUG = 0;
Logger.LEVEL_INFO = 1;
Logger.LEVEL_WARN = 2;
Logger.LEVEL_ERROR = 3;
Logger.DEFAULT_LEVEL = Logger.LEVEL_WARN;
if (GLib.getenv("SHELLTILE_DEBUG")){
Logger.DEFAULT_LEVEL = Logger.LEVEL_DEBUG;
}
Logger.getLogger = function (module){
return new Logger("[" + module + "]");
}