@reldens/utils 0.49.0 → 0.50.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 +13 -8
- package/package.json +1 -1
package/lib/logger.js
CHANGED
|
@@ -29,14 +29,13 @@ class Logger
|
|
|
29
29
|
this.callback = false;
|
|
30
30
|
this.forcedDisabled = Boolean(sc.get(context, 'RELDENS_LOGS_FORCED_DISABLED', false));
|
|
31
31
|
this.addTimeStamp = Boolean(sc.get(context, 'RELDENS_LOGS_INCLUDE_TIMESTAMP', true));
|
|
32
|
-
this.maxLogArgLength = sc.get(context, 'RELDENS_LOGS_MAX_ARGUMENT_LENGTH',
|
|
33
|
-
this.maxStackTraceLength = sc.get(context, 'RELDENS_LOGS_MAX_STACK_TRACE_LENGTH',
|
|
32
|
+
this.maxLogArgLength = sc.get(context, 'RELDENS_LOGS_MAX_ARGUMENT_LENGTH', 0);
|
|
33
|
+
this.maxStackTraceLength = sc.get(context, 'RELDENS_LOGS_MAX_STACK_TRACE_LENGTH', 0);
|
|
34
|
+
this.applySanitizer = Boolean(sc.get(context, 'RELDENS_LOGS_APPLY_SANITIZER', false));
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
context()
|
|
37
38
|
{
|
|
38
|
-
// @NOTE: any change on this method could break Parcel and you will end up with the following error.
|
|
39
|
-
// Failed to resolve module specifier "process"
|
|
40
39
|
let context = process.env;
|
|
41
40
|
if('undefined' !== typeof window){
|
|
42
41
|
return window;
|
|
@@ -95,8 +94,11 @@ class Logger
|
|
|
95
94
|
log(levelLabel, ...args)
|
|
96
95
|
{
|
|
97
96
|
let date = !this.addTimeStamp ? '' : (new Date()).toISOString().slice(0, 19).replace('T', ' ')+' - ';
|
|
98
|
-
let
|
|
99
|
-
this.
|
|
97
|
+
let processedArgs = args;
|
|
98
|
+
if(this.applySanitizer){
|
|
99
|
+
processedArgs = args.map(arg => sc.isString(arg) ? sc.cleanMessage(arg, this.maxLogArgLength) : arg);
|
|
100
|
+
}
|
|
101
|
+
this.logWithCallback(date+levelLabel.toUpperCase()+' -', ...processedArgs);
|
|
100
102
|
if(-1 !== this.enableTraceFor().indexOf('all') || -1 !== this.enableTraceFor().indexOf(levelLabel)){
|
|
101
103
|
if('function' !== typeof Error?.captureStackTrace){
|
|
102
104
|
this.logWithCallback('Error.captureStackTrace is not available.', typeof Error?.captureStackTrace);
|
|
@@ -104,8 +106,11 @@ class Logger
|
|
|
104
106
|
}
|
|
105
107
|
let stackHolder = {};
|
|
106
108
|
Error.captureStackTrace(stackHolder, levelLabel);
|
|
107
|
-
let
|
|
108
|
-
this.
|
|
109
|
+
let processedStack = stackHolder.stack;
|
|
110
|
+
if(this.applySanitizer){
|
|
111
|
+
processedStack = sc.cleanMessage(stackHolder.stack, this.maxStackTraceLength);
|
|
112
|
+
}
|
|
113
|
+
this.logWithCallback(processedStack);
|
|
109
114
|
}
|
|
110
115
|
return this;
|
|
111
116
|
}
|