@reldens/utils 0.10.0-beta.2 → 0.10.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/logger.js +78 -11
- package/package.json +1 -1
package/lib/logger.js
CHANGED
|
@@ -8,30 +8,97 @@
|
|
|
8
8
|
|
|
9
9
|
class Logger
|
|
10
10
|
{
|
|
11
|
+
logLevels = {
|
|
12
|
+
none: 0,
|
|
13
|
+
debug: 1, // debug-level messages
|
|
14
|
+
info: 2, // informational messages
|
|
15
|
+
notice: 3, // normal but significant condition
|
|
16
|
+
warning: 4, // warning conditions
|
|
17
|
+
error: 5, // error conditions
|
|
18
|
+
critical: 6, // critical conditions
|
|
19
|
+
alert: 7, // action must be taken immediately
|
|
20
|
+
emergency: 8, // system is unusable
|
|
21
|
+
};
|
|
11
22
|
|
|
12
23
|
constructor()
|
|
13
24
|
{
|
|
14
|
-
|
|
25
|
+
// @TODO - BETA
|
|
26
|
+
// - Implement different log systems (console.log, files logs, db log?).
|
|
27
|
+
// - Implement notifications system (email?), and make it configurable for the different log levels.
|
|
28
|
+
this.logLevel = process.env.RELDENS_LOG_LEVEL || 0;
|
|
29
|
+
this.enableTraceFor = (process.env.RELDENS_ENABLE_TRACE_FOR || '').split(',');
|
|
15
30
|
}
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
log(levelLabel, ...args)
|
|
18
33
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// - implement different log systems (console.log, files logs, db log?).
|
|
22
|
-
// - implement notifications system (email?), and make it configurable for the different log levels.
|
|
23
|
-
console.info('INFO -', ...args);
|
|
24
|
-
if(this.enableTrace.indexOf('info') !== -1){
|
|
34
|
+
console.log(levelLabel.toUpperCase()+' -', ...args);
|
|
35
|
+
if(this.enableTraceFor.indexOf(levelLabel) !== -1){
|
|
25
36
|
console.trace();
|
|
26
37
|
}
|
|
27
38
|
}
|
|
28
39
|
|
|
40
|
+
debug(...args)
|
|
41
|
+
{
|
|
42
|
+
if(1 > this.logLevel){
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.log('debug', ...args);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
info(...args)
|
|
49
|
+
{
|
|
50
|
+
if(2 > this.logLevel){
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.log('info', ...args);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
notice(...args)
|
|
57
|
+
{
|
|
58
|
+
if(3 > this.logLevel){
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.log('notice', ...args);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
warning(...args)
|
|
65
|
+
{
|
|
66
|
+
if(4 > this.logLevel){
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.log('warning', ...args);
|
|
70
|
+
}
|
|
71
|
+
|
|
29
72
|
error(...args)
|
|
30
73
|
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
74
|
+
if(5 > this.logLevel){
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.log('error', ...args);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
critical(...args)
|
|
81
|
+
{
|
|
82
|
+
if(6 > this.logLevel){
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
this.log('critical', ...args);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
alert(...args)
|
|
89
|
+
{
|
|
90
|
+
if(7 > this.logLevel){
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.log('alert', ...args);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
emergency(...args)
|
|
97
|
+
{
|
|
98
|
+
if(8 > this.logLevel){
|
|
99
|
+
return;
|
|
34
100
|
}
|
|
101
|
+
this.log('emergency', ...args);
|
|
35
102
|
}
|
|
36
103
|
|
|
37
104
|
}
|