mentie 0.1.7 → 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 CHANGED
@@ -2,6 +2,3 @@
2
2
 
3
3
  Mentor's favorite helpers.
4
4
 
5
- Notes:
6
-
7
- - If you're going to use promise utilities `make_retryable` and `throttle_and_retry`, make sure to install their dependencies: `npm i -S promise-retry promise-parallel-throttle`
@@ -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 ) ) console.log( ...messages )
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 ) ) console.info( ...messages )
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 ) ) console.warn( ...messages )
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mentie",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Mentor's toolbelt",
5
5
  "type": "module",
6
6
  "main": "index.js",