-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlogging.ts
More file actions
46 lines (37 loc) · 1.22 KB
/
Copy pathlogging.ts
File metadata and controls
46 lines (37 loc) · 1.22 KB
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
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { Logger } from "@utils/Logger";
export type LoggingLevel = "errors" | "info" | "debug";
const levelPriority: Record<LoggingLevel, number> = {
errors: 0,
info: 1,
debug: 2
};
let levelProvider: () => LoggingLevel = () => "errors";
export function setLoggingLevelProvider(provider: () => LoggingLevel) {
levelProvider = provider;
}
const baseLogger = new Logger("BigFileUpload", "#8caaee");
function shouldLog(level: Exclude<LoggingLevel, "errors">) {
const current = levelProvider();
return levelPriority[current] >= levelPriority[level];
}
export const pluginLogger = {
info: (...args: any[]) => {
if (shouldLog("info")) baseLogger.info(...args);
},
debug: (...args: any[]) => {
if (shouldLog("debug")) baseLogger.log("[debug]", ...args);
},
warn: (...args: any[]) => {
// Warnings shown at info level or above (not on "errors only" mode)
if (shouldLog("info")) baseLogger.warn(...args);
},
error: (...args: any[]) => {
baseLogger.error(...args);
}
};
export type PluginLogger = typeof pluginLogger;