@reldens/utils 0.36.0 → 0.38.0
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 +86 -18
- package/lib/shortcuts.js +1 -6
- package/package.json +2 -2
package/lib/logger.js
CHANGED
|
@@ -25,6 +25,10 @@ class Logger
|
|
|
25
25
|
// - Implement different log systems (console.log, files logs, db log?).
|
|
26
26
|
// - Implement notifications system (email?), and make it configurable for the different log levels.
|
|
27
27
|
let context = this.context();
|
|
28
|
+
this.enableTraceBack = '';
|
|
29
|
+
this.logLevelBack = 3;
|
|
30
|
+
this.forcedDisabled = Boolean(context.RELDENS_FORCED_DISABLED_LOGS || false);
|
|
31
|
+
this.addTimeStamp = Boolean(context.RELDENS_INCLUDE_LOGS_TIMESTAMP || true);
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
context()
|
|
@@ -38,6 +42,44 @@ class Logger
|
|
|
38
42
|
return context;
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
enableTraceAll()
|
|
46
|
+
{
|
|
47
|
+
this.enableTraceBack = this.context().RELDENS_ENABLE_TRACE_FOR;
|
|
48
|
+
this.context().RELDENS_ENABLE_TRACE_FOR = 'all';
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
restoreTraceFor()
|
|
53
|
+
{
|
|
54
|
+
this.context().RELDENS_ENABLE_TRACE_FOR = this.enableTraceBack;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
setLogLevel(level)
|
|
59
|
+
{
|
|
60
|
+
this.logLevelBack = this.context().RELDENS_LOG_LEVEL;
|
|
61
|
+
this.context().RELDENS_LOG_LEVEL = level;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
restoreLogLevel()
|
|
66
|
+
{
|
|
67
|
+
this.context().RELDENS_LOG_LEVEL = this.logLevelBack;
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setForcedDisabled(forced)
|
|
72
|
+
{
|
|
73
|
+
this.forcedDisabled = forced;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setAddTimeStamp(addTimeStamp)
|
|
78
|
+
{
|
|
79
|
+
this.addTimeStamp = addTimeStamp;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
41
83
|
logLevel()
|
|
42
84
|
{
|
|
43
85
|
return this.context().RELDENS_LOG_LEVEL || 0;
|
|
@@ -50,80 +92,106 @@ class Logger
|
|
|
50
92
|
|
|
51
93
|
log(levelLabel, ...args)
|
|
52
94
|
{
|
|
53
|
-
|
|
95
|
+
let date = !this.addTimeStamp ? '' : (new Date()).toISOString().slice(0, 19).replace('T', ' ')+' - ';
|
|
96
|
+
console.log(date+levelLabel.toUpperCase()+' -', ...args);
|
|
54
97
|
if(-1 !== this.enableTraceFor().indexOf('all') || -1 !== this.enableTraceFor().indexOf(levelLabel)){
|
|
55
98
|
if('function' !== typeof Error?.captureStackTrace){
|
|
56
99
|
console.log('Error.captureStackTrace is not available.', typeof Error?.captureStackTrace);
|
|
57
|
-
return;
|
|
100
|
+
return this;
|
|
58
101
|
}
|
|
59
102
|
let stackHolder = {};
|
|
60
103
|
Error.captureStackTrace(stackHolder, levelLabel);
|
|
61
104
|
console.log(stackHolder.stack);
|
|
62
105
|
}
|
|
106
|
+
return this;
|
|
63
107
|
}
|
|
64
108
|
|
|
65
109
|
debug(...args)
|
|
66
110
|
{
|
|
111
|
+
if(this.forcedDisabled){
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
67
114
|
if(8 > this.logLevel()){
|
|
68
|
-
return;
|
|
115
|
+
return this;
|
|
69
116
|
}
|
|
70
|
-
this.log('debug', ...args);
|
|
117
|
+
return this.log('debug', ...args);
|
|
71
118
|
}
|
|
72
119
|
|
|
73
120
|
info(...args)
|
|
74
121
|
{
|
|
122
|
+
if(this.forcedDisabled){
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
75
125
|
if(7 > this.logLevel()){
|
|
76
|
-
return;
|
|
126
|
+
return this;
|
|
77
127
|
}
|
|
78
|
-
this.log('info', ...args);
|
|
128
|
+
return this.log('info', ...args);
|
|
79
129
|
}
|
|
80
130
|
|
|
81
131
|
notice(...args)
|
|
82
132
|
{
|
|
133
|
+
if(this.forcedDisabled){
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
83
136
|
if(6 > this.logLevel()){
|
|
84
|
-
return;
|
|
137
|
+
return this;
|
|
85
138
|
}
|
|
86
|
-
this.log('notice', ...args);
|
|
139
|
+
return this.log('notice', ...args);
|
|
87
140
|
}
|
|
88
141
|
|
|
89
142
|
warning(...args)
|
|
90
143
|
{
|
|
144
|
+
if(this.forcedDisabled){
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
91
147
|
if(5 > this.logLevel()){
|
|
92
|
-
return;
|
|
148
|
+
return this;
|
|
93
149
|
}
|
|
94
|
-
this.log('warning', ...args);
|
|
150
|
+
return this.log('warning', ...args);
|
|
95
151
|
}
|
|
96
152
|
|
|
97
153
|
error(...args)
|
|
98
154
|
{
|
|
155
|
+
if(this.forcedDisabled){
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
99
158
|
if(4 > this.logLevel()){
|
|
100
|
-
return;
|
|
159
|
+
return this;
|
|
101
160
|
}
|
|
102
|
-
this.log('error', ...args);
|
|
161
|
+
return this.log('error', ...args);
|
|
103
162
|
}
|
|
104
163
|
|
|
105
164
|
critical(...args)
|
|
106
165
|
{
|
|
166
|
+
if(this.forcedDisabled){
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
107
169
|
if(3 > this.logLevel()){
|
|
108
|
-
return;
|
|
170
|
+
return this;
|
|
109
171
|
}
|
|
110
|
-
this.log('critical', ...args);
|
|
172
|
+
return this.log('critical', ...args);
|
|
111
173
|
}
|
|
112
174
|
|
|
113
175
|
alert(...args)
|
|
114
176
|
{
|
|
177
|
+
if(this.forcedDisabled){
|
|
178
|
+
return this;
|
|
179
|
+
}
|
|
115
180
|
if(2 > this.logLevel()){
|
|
116
|
-
return;
|
|
181
|
+
return this;
|
|
117
182
|
}
|
|
118
|
-
this.log('alert', ...args);
|
|
183
|
+
return this.log('alert', ...args);
|
|
119
184
|
}
|
|
120
185
|
|
|
121
186
|
emergency(...args)
|
|
122
187
|
{
|
|
188
|
+
if(this.forcedDisabled){
|
|
189
|
+
return this;
|
|
190
|
+
}
|
|
123
191
|
if(1 > this.logLevel()){
|
|
124
|
-
return;
|
|
192
|
+
return this;
|
|
125
193
|
}
|
|
126
|
-
this.log('emergency', ...args);
|
|
194
|
+
return this.log('emergency', ...args);
|
|
127
195
|
}
|
|
128
196
|
|
|
129
197
|
}
|
package/lib/shortcuts.js
CHANGED
|
@@ -338,7 +338,7 @@ class Shortcuts
|
|
|
338
338
|
|
|
339
339
|
roundToPrecision(number, precision = 4)
|
|
340
340
|
{
|
|
341
|
-
return Number(number.toFixed(precision));
|
|
341
|
+
return Number(Number(number).toFixed(precision));
|
|
342
342
|
}
|
|
343
343
|
|
|
344
344
|
randomValueFromArray(array)
|
|
@@ -384,11 +384,6 @@ class Shortcuts
|
|
|
384
384
|
return result;
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
numberWithDecimals(number, decimals = 0)
|
|
388
|
-
{
|
|
389
|
-
return Number(Number(number).toFixed(decimals));
|
|
390
|
-
}
|
|
391
|
-
|
|
392
387
|
cleanMessage(message, characterLimit)
|
|
393
388
|
{
|
|
394
389
|
if(!message){
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reldens/utils",
|
|
3
3
|
"scope": "@reldens",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.38.0",
|
|
5
5
|
"description": "Reldens - Utils",
|
|
6
6
|
"author": "Damian A. Pastorini",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"url": "https://github.com/damian-pastorini/reldens-utils/issues"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"await-event-emitter": "
|
|
38
|
+
"await-event-emitter": "2.0.2"
|
|
39
39
|
}
|
|
40
40
|
}
|