-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
32 lines (28 loc) · 798 Bytes
/
utils.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
// Usage example:
// const logger = new LitLogger("[CustomPrefix]");
// logger.log("This is a log message");
// logger.throwError('This is an error message');
export class LitLogger {
PREFIX: string;
static orange = "\x1b[33m";
static reset = "\x1b[0m";
static red = "\x1b[31m";
debug: boolean;
constructor(prefix = "[PKPCosmosSigner]", debug = false) {
this.PREFIX = prefix;
this.debug = debug;
}
log(...args: any[]) {
if (!this.debug) return;
console.log(LitLogger.orange + this.PREFIX + LitLogger.reset, ...args);
}
throwError(message: string): never {
if (this.debug) {
console.error(
LitLogger.orange + this.PREFIX + LitLogger.reset,
LitLogger.red + message + LitLogger.reset
);
}
throw new Error(message);
}
}