@reldens/utils 0.21.1 → 0.22.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.
Files changed (2) hide show
  1. package/lib/logger.js +25 -15
  2. package/package.json +1 -1
package/lib/logger.js CHANGED
@@ -25,8 +25,6 @@ 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.logLevel = context.RELDENS_LOG_LEVEL || 0;
29
- this.enableTraceFor = (context.RELDENS_ENABLE_TRACE_FOR || '').split(',');
30
28
  }
31
29
 
32
30
  context()
@@ -40,21 +38,33 @@ class Logger
40
38
  return context;
41
39
  }
42
40
 
41
+ logLevel()
42
+ {
43
+ return this.context().RELDENS_LOG_LEVEL || 0;
44
+ }
45
+
46
+ enableTraceFor()
47
+ {
48
+ return (this.context().RELDENS_ENABLE_TRACE_FOR || '').split(',');
49
+ }
50
+
43
51
  log(levelLabel, ...args)
44
52
  {
45
53
  console.log(levelLabel.toUpperCase()+' -', ...args);
46
- if(-1 !== this.enableTraceFor.indexOf('all') || -1 !== this.enableTraceFor.indexOf(levelLabel)){
47
- if('function' === typeof Error.captureStackTrace){
48
- let stackHolder = {};
49
- Error.captureStackTrace(stackHolder, levelLabel);
50
- console.log(stackHolder.stack);
54
+ if(-1 !== this.enableTraceFor().indexOf('all') || -1 !== this.enableTraceFor().indexOf(levelLabel)){
55
+ if('function' !== typeof Error?.captureStackTrace){
56
+ console.log('Error.captureStackTrace is not available.', typeof Error?.captureStackTrace);
57
+ return;
51
58
  }
59
+ let stackHolder = {};
60
+ Error.captureStackTrace(stackHolder, levelLabel);
61
+ console.log(stackHolder.stack);
52
62
  }
53
63
  }
54
64
 
55
65
  debug(...args)
56
66
  {
57
- if(8 > this.logLevel){
67
+ if(8 > this.logLevel()){
58
68
  return;
59
69
  }
60
70
  this.log('debug', ...args);
@@ -62,7 +72,7 @@ class Logger
62
72
 
63
73
  info(...args)
64
74
  {
65
- if(7 > this.logLevel){
75
+ if(7 > this.logLevel()){
66
76
  return;
67
77
  }
68
78
  this.log('info', ...args);
@@ -70,7 +80,7 @@ class Logger
70
80
 
71
81
  notice(...args)
72
82
  {
73
- if(6 > this.logLevel){
83
+ if(6 > this.logLevel()){
74
84
  return;
75
85
  }
76
86
  this.log('notice', ...args);
@@ -78,7 +88,7 @@ class Logger
78
88
 
79
89
  warning(...args)
80
90
  {
81
- if(5 > this.logLevel){
91
+ if(5 > this.logLevel()){
82
92
  return;
83
93
  }
84
94
  this.log('warning', ...args);
@@ -86,7 +96,7 @@ class Logger
86
96
 
87
97
  error(...args)
88
98
  {
89
- if(4 > this.logLevel){
99
+ if(4 > this.logLevel()){
90
100
  return;
91
101
  }
92
102
  this.log('error', ...args);
@@ -94,7 +104,7 @@ class Logger
94
104
 
95
105
  critical(...args)
96
106
  {
97
- if(3 > this.logLevel){
107
+ if(3 > this.logLevel()){
98
108
  return;
99
109
  }
100
110
  this.log('critical', ...args);
@@ -102,7 +112,7 @@ class Logger
102
112
 
103
113
  alert(...args)
104
114
  {
105
- if(2 > this.logLevel){
115
+ if(2 > this.logLevel()){
106
116
  return;
107
117
  }
108
118
  this.log('alert', ...args);
@@ -110,7 +120,7 @@ class Logger
110
120
 
111
121
  emergency(...args)
112
122
  {
113
- if(1 > this.logLevel){
123
+ if(1 > this.logLevel()){
114
124
  return;
115
125
  }
116
126
  this.log('emergency', ...args);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/utils",
3
3
  "scope": "@reldens",
4
- "version": "0.21.1",
4
+ "version": "0.22.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",