@reldens/utils 0.40.0 → 0.41.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 CHANGED
@@ -9,7 +9,7 @@ class Logger
9
9
 
10
10
  logLevels = {
11
11
  none: 0,
12
- emergency: 1, // system is unusable
12
+ emergency: 1, // the system is unusable
13
13
  alert: 2, // action must be taken immediately
14
14
  critical: 3, // critical conditions
15
15
  error: 4, // error conditions
@@ -29,6 +29,7 @@ class Logger
29
29
  this.logLevelBack = 3;
30
30
  this.forcedDisabled = Boolean(context.RELDENS_FORCED_DISABLED_LOGS || false);
31
31
  this.addTimeStamp = Boolean(context.RELDENS_INCLUDE_LOGS_TIMESTAMP || true);
32
+ this.callback = false;
32
33
  }
33
34
 
34
35
  context()
@@ -93,19 +94,27 @@ class Logger
93
94
  log(levelLabel, ...args)
94
95
  {
95
96
  let date = !this.addTimeStamp ? '' : (new Date()).toISOString().slice(0, 19).replace('T', ' ')+' - ';
96
- console.log(date+levelLabel.toUpperCase()+' -', ...args);
97
+ this.logWithCallback(date+levelLabel.toUpperCase()+' -', ...args);
97
98
  if(-1 !== this.enableTraceFor().indexOf('all') || -1 !== this.enableTraceFor().indexOf(levelLabel)){
98
99
  if('function' !== typeof Error?.captureStackTrace){
99
- console.log('Error.captureStackTrace is not available.', typeof Error?.captureStackTrace);
100
+ this.logWithCallback('Error.captureStackTrace is not available.', typeof Error?.captureStackTrace);
100
101
  return this;
101
102
  }
102
103
  let stackHolder = {};
103
104
  Error.captureStackTrace(stackHolder, levelLabel);
104
- console.log(stackHolder.stack);
105
+ this.logWithCallback(stackHolder.stack);
105
106
  }
106
107
  return this;
107
108
  }
108
109
 
110
+ logWithCallback(...args)
111
+ {
112
+ if('function' === typeof this.callback){
113
+ this.callback(...args);
114
+ }
115
+ console.log(...args);
116
+ }
117
+
109
118
  debug(...args)
110
119
  {
111
120
  if(this.forcedDisabled){
package/lib/shortcuts.js CHANGED
@@ -49,7 +49,7 @@ class Shortcuts
49
49
 
50
50
  isFunction(callback)
51
51
  {
52
- return callback && 'function' === typeof callback;
52
+ return (callback && 'function' === typeof callback);
53
53
  }
54
54
 
55
55
  isObjectFunction(obj, property)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reldens/utils",
3
3
  "scope": "@reldens",
4
- "version": "0.40.0",
4
+ "version": "0.41.0",
5
5
  "description": "Reldens - Utils",
6
6
  "author": "Damian A. Pastorini",
7
7
  "license": "MIT",