mentie 0.1.7 → 0.1.9
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/README.md +0 -3
- package/modules/logging.js +59 -3
- package/package.json +1 -1
package/README.md
CHANGED
package/modules/logging.js
CHANGED
|
@@ -13,6 +13,38 @@ const should_log = levels => {
|
|
|
13
13
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const add_trace = messages => {
|
|
17
|
+
|
|
18
|
+
// Try to add stack to messages if needed
|
|
19
|
+
try {
|
|
20
|
+
|
|
21
|
+
// Do nothing if we are not in a browser
|
|
22
|
+
if( typeof window === 'undefined' ) return messages
|
|
23
|
+
|
|
24
|
+
// If there is no trace=true in the url, do nothing
|
|
25
|
+
if( !window.location?.search?.includes?.( 'trace=true' ) ) return messages
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// Get the stack trace
|
|
29
|
+
let { stack } = new Error()
|
|
30
|
+
|
|
31
|
+
// Remove the first line of the stack trace
|
|
32
|
+
stack = stack.split( '\n' ).slice( 1 ).join( '\n' )
|
|
33
|
+
|
|
34
|
+
// Add the trace to the messages
|
|
35
|
+
messages.push( { stack } )
|
|
36
|
+
|
|
37
|
+
return messages
|
|
38
|
+
|
|
39
|
+
} catch ( error ) {
|
|
40
|
+
|
|
41
|
+
// This should never happen but we'll add it so we don't crash in unexpected situations
|
|
42
|
+
return messages
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
16
48
|
/**
|
|
17
49
|
* Logs the provided messages to the console.
|
|
18
50
|
* Only logs in development mode OR if ?loglevel= or LOG_LEVEL= is set to one of the following: 'error', 'warn', 'info'.
|
|
@@ -30,7 +62,15 @@ export function log( ...messages ) {
|
|
|
30
62
|
const levels = [ 'info' ]
|
|
31
63
|
|
|
32
64
|
// Log the messages if the loglevel matches
|
|
33
|
-
if( dev || should_log( levels ) )
|
|
65
|
+
if( dev || should_log( levels ) ) {
|
|
66
|
+
|
|
67
|
+
// Add the trace to the messages
|
|
68
|
+
add_trace( messages )
|
|
69
|
+
|
|
70
|
+
// Log the messages
|
|
71
|
+
console.log( ...messages )
|
|
72
|
+
|
|
73
|
+
}
|
|
34
74
|
|
|
35
75
|
}
|
|
36
76
|
|
|
@@ -47,7 +87,15 @@ log.info = function( ...messages ) {
|
|
|
47
87
|
const levels = [ 'info' ]
|
|
48
88
|
|
|
49
89
|
// Log the messages if the loglevel matches
|
|
50
|
-
if( is_emulator || should_log( levels ) )
|
|
90
|
+
if( is_emulator || should_log( levels ) ) {
|
|
91
|
+
|
|
92
|
+
// Add the trace to the messages
|
|
93
|
+
add_trace( messages )
|
|
94
|
+
|
|
95
|
+
// Log the messages
|
|
96
|
+
console.info( ...messages )
|
|
97
|
+
|
|
98
|
+
}
|
|
51
99
|
|
|
52
100
|
}
|
|
53
101
|
|
|
@@ -64,7 +112,15 @@ log.warn = function( ...messages ) {
|
|
|
64
112
|
const levels = [ 'warn', 'info' ]
|
|
65
113
|
|
|
66
114
|
// Log the messages if the loglevel matches
|
|
67
|
-
if( dev || should_log( levels ) )
|
|
115
|
+
if( dev || should_log( levels ) ) {
|
|
116
|
+
|
|
117
|
+
// Add the trace to the messages
|
|
118
|
+
add_trace( messages )
|
|
119
|
+
|
|
120
|
+
// Log the messages
|
|
121
|
+
console.warn( ...messages )
|
|
122
|
+
|
|
123
|
+
}
|
|
68
124
|
|
|
69
125
|
}
|
|
70
126
|
|