-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
debug.js
55 lines (47 loc) · 1.01 KB
/
debug.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {getDebugMode} from './config.js'
const LogLevel = {
ERROR: "error",
WARN: "warn",
INFO: "info",
DEBUG: "debug",
}
let debugMode = false;
getDebugMode().then(val => {
debugMode = val
})
function log(level, ...args) {
switch (level) {
case LogLevel.ERROR:
console.error(...args)
break
case LogLevel.WARN:
console.warn(...args)
break
case LogLevel.INFO:
console.info(...args)
break
case LogLevel.DEBUG:
console.debug(...args)
break
}
if (debugMode) {
chrome.runtime.sendMessage({type: "log", level: level, content: args})
}
}
export function error(...args) {
log(LogLevel.ERROR, ...args)
}
export function warn(...args) {
log(LogLevel.WARN, ...args)
}
export function info(...args) {
log(LogLevel.INFO, ...args)
}
export function debug(...args) {
log(LogLevel.DEBUG, ...args)
}
chrome.storage.onChanged.addListener((changes, areaName) => {
if ("debug-mode" in changes) {
debugMode = changes["debug-mode"].newValue
}
})