-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogger.ts
More file actions
54 lines (44 loc) · 1.25 KB
/
Copy pathlogger.ts
File metadata and controls
54 lines (44 loc) · 1.25 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
47
48
49
50
51
52
53
54
import { Platform } from 'obsidian';
export enum LogLevel {
NONE = 0,
ERROR = 1,
WARN = 2,
INFO = 3,
DEBUG = 4
}
export class Logger {
private static instance: Logger;
private logLevel: LogLevel = LogLevel.ERROR;
private readonly prefix: string = '[Save Images Offline]';
private constructor() {}
public static getInstance(): Logger {
if (!Logger.instance) {
Logger.instance = new Logger();
}
return Logger.instance;
}
public setLogLevel(level: LogLevel): void {
this.logLevel = level;
}
public debug(message: string): void {
if (this.logLevel >= LogLevel.DEBUG) {
console.debug(`${this.prefix} ${message}`);
}
}
public info(message: string): void {
if (this.logLevel >= LogLevel.INFO) {
console.info(`${this.prefix} ${message}`);
}
}
public warn(message: string): void {
if (this.logLevel >= LogLevel.WARN) {
console.warn(`${this.prefix} ${message}`);
}
}
public error(message: string): void {
if (this.logLevel >= LogLevel.ERROR) {
console.error(`${this.prefix} ${message}`);
}
}
}
export const log = Logger.getInstance();