egonlog 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +8 -5
- package/dist/index.js +9 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export type LogLevel = "error" | "warn" | "info" | "debug";
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export type EgonLogConfig = {
|
|
3
|
+
logLevel: LogLevel;
|
|
4
|
+
};
|
|
5
|
+
export declare class EgonLog {
|
|
6
|
+
private logLevel;
|
|
4
7
|
private timers;
|
|
5
|
-
constructor(
|
|
8
|
+
constructor(config: EgonLogConfig);
|
|
6
9
|
private shouldLog;
|
|
7
10
|
private log;
|
|
8
11
|
error(...args: unknown[]): void;
|
|
@@ -11,8 +14,8 @@ export declare class Logger {
|
|
|
11
14
|
debug(...args: unknown[]): void;
|
|
12
15
|
table(...args: unknown[]): void;
|
|
13
16
|
highlight(...args: unknown[]): void;
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
setLogLevel(level: LogLevel): void;
|
|
18
|
+
getLogLevel(): LogLevel;
|
|
16
19
|
startTimer(label: string): void;
|
|
17
20
|
endTimer(label: string): void;
|
|
18
21
|
time<T>(label: string, fn: () => Promise<T>): Promise<T>;
|
package/dist/index.js
CHANGED
|
@@ -5,14 +5,14 @@ const LOG_LEVELS = {
|
|
|
5
5
|
info: 2,
|
|
6
6
|
debug: 3,
|
|
7
7
|
};
|
|
8
|
-
export class
|
|
9
|
-
|
|
8
|
+
export class EgonLog {
|
|
9
|
+
logLevel;
|
|
10
10
|
timers = {};
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.logLevel = config.logLevel;
|
|
13
13
|
}
|
|
14
14
|
shouldLog(messageLevel) {
|
|
15
|
-
return LOG_LEVELS[messageLevel] <= LOG_LEVELS[this.
|
|
15
|
+
return LOG_LEVELS[messageLevel] <= LOG_LEVELS[this.logLevel];
|
|
16
16
|
}
|
|
17
17
|
log(level, ...args) {
|
|
18
18
|
if (!this.shouldLog(level)) {
|
|
@@ -60,11 +60,11 @@ export class Logger {
|
|
|
60
60
|
const highlighted = args.map((arg) => typeof arg === "string" ? color.bgWhite.black(arg) : arg);
|
|
61
61
|
console.log(...highlighted);
|
|
62
62
|
}
|
|
63
|
-
|
|
64
|
-
this.
|
|
63
|
+
setLogLevel(level) {
|
|
64
|
+
this.logLevel = level;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
return this.
|
|
66
|
+
getLogLevel() {
|
|
67
|
+
return this.logLevel;
|
|
68
68
|
}
|
|
69
69
|
startTimer(label) {
|
|
70
70
|
this.timers[label] = performance.now();
|