From 991fb36011b083decb659374dbc81646b6c8434a Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 26 Mar 2023 20:54:09 +0300 Subject: [PATCH] loglevel helpers --- src/LoggerClient.js | 4 ++++ src/MasterLogger.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/LoggerClient.js b/src/LoggerClient.js index e40d1f2..05aa0cc 100644 --- a/src/LoggerClient.js +++ b/src/LoggerClient.js @@ -36,6 +36,10 @@ class LoggerClient { return this.#_logLevel; } + get logLevels () { + return Object.keys(this.#_logLevelMapping); + } + setLogLevel (level = 'info') { if (typeof level === 'number') this.#_logLevel = level; diff --git a/src/MasterLogger.js b/src/MasterLogger.js index 808d922..3493cdf 100644 --- a/src/MasterLogger.js +++ b/src/MasterLogger.js @@ -54,6 +54,23 @@ class MasterLogger { } + get logLevel () { + return this.#_logLevel; + } + + get logLevels () { + return Object.keys(this.#_logLevelMapping); + } + + setLogLevel (level = 'info') { + if (typeof level === 'number') + this.#_logLevel = level; + else if (typeof level === 'string') + this.#_logLevel = this.#_logLevelMapping[level.toLowerCase()]; + else + throw new Error(`Invalid log level type, expected string or number, got ${typeof level}`); + } + attach (shard) { shard.on('message', (msg) => { if (!msg[this.#_guard])