mentie 0.1.6 → 0.1.8
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/environment.js +1 -1
- package/modules/logging.js +53 -3
- package/package.json +1 -1
package/README.md
CHANGED
package/modules/environment.js
CHANGED
|
@@ -49,7 +49,7 @@ export const node_loglevel = typeof process !== 'undefined' && process.env?.LOG_
|
|
|
49
49
|
* The log level used in the environment.
|
|
50
50
|
* @type {string}
|
|
51
51
|
*/
|
|
52
|
-
export const loglevel = web_loglevel || node_loglevel || 'info'
|
|
52
|
+
export const loglevel = web_loglevel || node_loglevel || dev ? 'info' : 'error'
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
/**
|
package/modules/logging.js
CHANGED
|
@@ -13,6 +13,32 @@ const should_log = levels => {
|
|
|
13
13
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
const add_trace = messages => {
|
|
17
|
+
|
|
18
|
+
// Do nothing if we are not in a browser
|
|
19
|
+
if( typeof window === 'undefined' ) return null
|
|
20
|
+
|
|
21
|
+
// Try to add stack to messages
|
|
22
|
+
try {
|
|
23
|
+
|
|
24
|
+
// Get the stack trace
|
|
25
|
+
let { stack } = new Error()
|
|
26
|
+
|
|
27
|
+
// Remove the first line of the stack trace as it is always the error message
|
|
28
|
+
stack = stack.split( '\n' ).slice( 1 ).join( '\n' )
|
|
29
|
+
|
|
30
|
+
// Add the trace to the messages
|
|
31
|
+
messages.push( { stack } )
|
|
32
|
+
|
|
33
|
+
} catch ( error ) {
|
|
34
|
+
|
|
35
|
+
// This should never happen but we'll add it so we don't crash in unexpected situations
|
|
36
|
+
return messages
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
16
42
|
/**
|
|
17
43
|
* Logs the provided messages to the console.
|
|
18
44
|
* Only logs in development mode OR if ?loglevel= or LOG_LEVEL= is set to one of the following: 'error', 'warn', 'info'.
|
|
@@ -30,7 +56,15 @@ export function log( ...messages ) {
|
|
|
30
56
|
const levels = [ 'info' ]
|
|
31
57
|
|
|
32
58
|
// Log the messages if the loglevel matches
|
|
33
|
-
if( dev || should_log( levels ) )
|
|
59
|
+
if( dev || should_log( levels ) ) {
|
|
60
|
+
|
|
61
|
+
// Add the trace to the messages
|
|
62
|
+
add_trace( messages )
|
|
63
|
+
|
|
64
|
+
// Log the messages
|
|
65
|
+
console.log( ...messages )
|
|
66
|
+
|
|
67
|
+
}
|
|
34
68
|
|
|
35
69
|
}
|
|
36
70
|
|
|
@@ -47,7 +81,15 @@ log.info = function( ...messages ) {
|
|
|
47
81
|
const levels = [ 'info' ]
|
|
48
82
|
|
|
49
83
|
// Log the messages if the loglevel matches
|
|
50
|
-
if( is_emulator || should_log( levels ) )
|
|
84
|
+
if( is_emulator || should_log( levels ) ) {
|
|
85
|
+
|
|
86
|
+
// Add the trace to the messages
|
|
87
|
+
add_trace( messages )
|
|
88
|
+
|
|
89
|
+
// Log the messages
|
|
90
|
+
console.info( ...messages )
|
|
91
|
+
|
|
92
|
+
}
|
|
51
93
|
|
|
52
94
|
}
|
|
53
95
|
|
|
@@ -64,7 +106,15 @@ log.warn = function( ...messages ) {
|
|
|
64
106
|
const levels = [ 'warn', 'info' ]
|
|
65
107
|
|
|
66
108
|
// Log the messages if the loglevel matches
|
|
67
|
-
if( dev || should_log( levels ) )
|
|
109
|
+
if( dev || should_log( levels ) ) {
|
|
110
|
+
|
|
111
|
+
// Add the trace to the messages
|
|
112
|
+
add_trace( messages )
|
|
113
|
+
|
|
114
|
+
// Log the messages
|
|
115
|
+
console.warn( ...messages )
|
|
116
|
+
|
|
117
|
+
}
|
|
68
118
|
|
|
69
119
|
}
|
|
70
120
|
|