-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathlog.ts
54 lines (44 loc) · 1.38 KB
/
log.ts
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
/* eslint-disable no-console */
import {STORAGE_CALLS_CLIENT_LOGS_KEY} from 'src/constants';
import {pluginId} from './manifest';
let clientLogs = '';
function appendClientLog(level: string, ...args: unknown[]) {
clientLogs += `${level} [${new Date().toISOString()}] ${args}\n`;
}
export function persistClientLogs() {
const storage = window.desktop ? localStorage : sessionStorage;
storage.setItem(STORAGE_CALLS_CLIENT_LOGS_KEY, clientLogs);
clientLogs = '';
}
export function getClientLogs() {
const storage = window.desktop ? localStorage : sessionStorage;
return storage.getItem(STORAGE_CALLS_CLIENT_LOGS_KEY) || '';
}
export function logErr(...args: unknown[]) {
console.error(`${pluginId}:`, ...args);
try {
if (window.callsClient) {
appendClientLog('error', ...args);
}
} catch (err) {
console.error(err);
}
}
export function logWarn(...args: unknown[]) {
console.warn(`${pluginId}:`, ...args);
if (window.callsClient) {
appendClientLog('warn', ...args);
}
}
export function logInfo(...args: unknown[]) {
console.info(`${pluginId}:`, ...args);
if (window.callsClient) {
appendClientLog('info', ...args);
}
}
export function logDebug(...args: unknown[]) {
console.debug(`${pluginId}:`, ...args);
if (window.callsClient) {
appendClientLog('debug', ...args);
}
}