-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (34 loc) · 884 Bytes
/
Copy pathindex.js
File metadata and controls
39 lines (34 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
export default class DebugConsoleLogs {
constructor({
nameSpace = 'debug-console-logs',
browserKey = '__debug__',
enable = false
} = {}) {
this._nameSpace = nameSpace
this._isDebug = enable || DebugConsoleLogs.isDebug(nameSpace, browserKey)
}
static isDebug(nameSpace, browserKey) {
if (typeof window === 'undefined') {
if (process.env.DEBUG === '*') return true
return (
(process.env.DEBUG &&
process.env.DEBUG.split(',').includes(nameSpace)) ||
false
)
}
return (
(window.localStorage &&
window.localStorage.getItem(browserKey) === '1') ||
false
)
}
_printLogs(mode, args) {
if (this._isDebug) console[mode](`[${this._nameSpace}]: `, ...args)
}
log(...args) {
this._printLogs('log', args)
}
error(...args) {
this._printLogs('error', args)
}
}