mentie 0.1.0 → 0.1.2

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.
@@ -34,13 +34,13 @@ export const dev = node_dev || web_dev
34
34
 
35
35
  /**
36
36
  * The log level for web applications.
37
- * @type {string}
37
+ * @type {string} - Log level. Valid values are: 'info', 'warn', 'error'
38
38
  */
39
39
  export const web_loglevel = is_web && new URLSearchParams( location?.search ).get( 'loglevel' )
40
40
 
41
41
  /**
42
42
  * The log level for the Node environment.
43
- * @type {string}
43
+ * @type {string} - Log level. Valid values are: 'info', 'warn', 'error'
44
44
  */
45
45
  export const node_loglevel = process.env?.LOG_LEVEL
46
46
 
@@ -1,5 +1,17 @@
1
1
  // Import environment data
2
- import { dev, loglevel } from "./environment.js"
2
+ import { dev, is_emulator, loglevel } from "./environment.js"
3
+
4
+ const should_log = levels => {
5
+
6
+ // Check if the loglevel matches this call
7
+ const valid_levels = [ 'info', 'warn', 'error' ]
8
+
9
+ // Check if the loglevel is valid
10
+ if( !valid_levels.includes( loglevel ) ) console.warn( `Invalid log level: ${ loglevel }` )
11
+
12
+ return levels.includes( loglevel )
13
+
14
+ }
3
15
 
4
16
  /**
5
17
  * Logs the provided messages to the console.
@@ -16,16 +28,15 @@ export function log( ...messages ) {
16
28
 
17
29
  // Check if the loglevel matches this call
18
30
  const levels = [ 'info' ]
19
- const should_log = dev || levels.includes( loglevel )
20
31
 
21
32
  // Log the messages if the loglevel matches
22
- if( should_log ) console.log( ...messages )
33
+ if( dev || should_log( levels ) ) console.log( ...messages )
23
34
 
24
35
  }
25
36
 
26
37
  /**
27
38
  * Logs the provided info messages to the console.
28
- * Only logs if ?loglevel= or LOG_LEVEL= is set to: 'info'
39
+ * Only logs in firebase emulator or if ?loglevel= or LOG_LEVEL= is set to: 'info'
29
40
  * 🎯 Goal: log info trace messages used only for extremely granular debugging
30
41
  * @example log.info( `Retreived key '${ key }' of type '${ typeof key }' from localstorage: `, cache )
31
42
  * @param {...any} messages - The messages to be logged.
@@ -34,10 +45,9 @@ log.info = function( ...messages ) {
34
45
 
35
46
  // Check if the loglevel matches this call
36
47
  const levels = [ 'info' ]
37
- const should_log = levels.includes( loglevel )
38
48
 
39
49
  // Log the messages if the loglevel matches
40
- if( should_log ) console.info( ...messages )
50
+ if( is_emulator || should_log( levels ) ) console.info( ...messages )
41
51
 
42
52
  }
43
53
 
@@ -52,10 +62,9 @@ log.warn = function( ...messages ) {
52
62
 
53
63
  // Check if the loglevel matches this call
54
64
  const levels = [ 'warn', 'info' ]
55
- const should_log = dev || levels.includes( loglevel )
56
65
 
57
66
  // Log the messages if the loglevel matches
58
- if( should_log ) console.warn( ...messages )
67
+ if( dev || should_log( levels ) ) console.warn( ...messages )
59
68
 
60
69
  }
61
70
 
@@ -71,7 +80,7 @@ log.error = function( ...messages ) {
71
80
  // Check if the loglevel matches this call
72
81
  const levels = [ 'error', 'warn', 'info' ]
73
82
  const should_log = dev || levels.includes( loglevel )
74
- if( !should_log ) return
83
+ if( !dev || !should_log ) return
75
84
 
76
85
  // Log the messages if the loglevel matches
77
86
  console.error( ...messages )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mentie",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Mentor's toolbelt",
5
5
  "type": "module",
6
6
  "main": "index.js",