Skip to content

Commit

Permalink
Fixed logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmaranan committed Oct 22, 2023
1 parent d231533 commit a00b0c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/prefs/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class SettingsPage extends PreferencesPage {
settings,
bind: "log-level",
items: Object.entries(Logger.LOG_LEVELS).map(([name, id]) => ({ id, name })),
type: "u",
}),
],
});
Expand Down
23 changes: 13 additions & 10 deletions lib/shared/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ export class Logger {
}

static get #level() {
return !(this.#settings?.get_boolean?.("logging-enabled") || !production)
? Logger.LOG_LEVELS.OFF
: this.#settings?.get_uint?.("log-level") ?? Infinity;
if (this.#settings?.get_boolean?.("logging-enabled")) {
return production
? Logger.LOG_LEVELS.OFF
: this.#settings?.get_string?.("log-level") ?? Infinity;
}
return Logger.LOG_LEVELS.OFF;
}

// TODO: use console.* methods
Expand All @@ -48,30 +51,30 @@ export class Logger {
}

static fatal(...args) {
if (this.#level > Logger.LOG_LEVELS.OFF) console.error(`[Forge] [FATAL]`, ...args);
if (this.#level > Logger.LOG_LEVELS.OFF) log(`[Forge] [FATAL]`, ...args);
}

static error(...args) {
if (this.#level > Logger.LOG_LEVELS.FATAL) console.error(`[Forge] [ERROR]`, ...args);
if (this.#level > Logger.LOG_LEVELS.FATAL) log(`[Forge] [ERROR]`, ...args);
}

static warn(...args) {
if (!this.#level > Logger.LOG_LEVELS.ERROR) console.warn(`[Forge] [WARN]`, ...args);
if (this.#level > Logger.LOG_LEVELS.ERROR) log(`[Forge] [WARN]`, ...args);
}

static info(...args) {
if (!this.#level > Logger.LOG_LEVELS.WARN) console.info(`[Forge] [INFO]`, ...args);
if (this.#level > Logger.LOG_LEVELS.WARN) log(`[Forge] [INFO]`, ...args);
}

static debug(...args) {
if (!this.#level > Logger.LOG_LEVELS.INFO) console.debug(`[Forge] [DEBUG]`, ...args);
if (this.#level > Logger.LOG_LEVELS.INFO) log(`[Forge] [DEBUG]`, ...args);
}

static trace(...args) {
if (!this.#level > Logger.LOG_LEVELS.DEBUG) console.debug(`[Forge] [TRACE]`, ...args);
if (this.#level > Logger.LOG_LEVELS.DEBUG) log(`[Forge] [TRACE]`, ...args);
}

static log(...args) {
if (!this.#level > Logger.LOG_LEVELS.OFF) console.log(`[Forge] [LOG]`, ...args);
if (this.#level > Logger.LOG_LEVELS.OFF) log(`[Forge] [LOG]`, ...args);
}
}

0 comments on commit a00b0c9

Please sign in to comment.