diff --git a/src/LoggerClient.ts b/src/LoggerClient.ts index 257ba87..9b0945a 100644 --- a/src/LoggerClient.ts +++ b/src/LoggerClient.ts @@ -46,16 +46,19 @@ class LoggerClient implements Logger const { customTypes = [] } = opts; this.#types = [ ...customTypes, ...Defaults.Types ]; - for (const type of this.#types) + this.#_logLevelMapping = { ...Defaults.ClientOptions.logLevelMapping, ...opts.logLevelMapping }; + this.#_guard = opts.guard || Defaults.ClientOptions.guard as string; + this.#_logLevel = opts.logLevel ?? Defaults.ClientOptions.logLevel as number; + + for (const type of this.#types) { + if (typeof this.#_logLevelMapping[type] === 'undefined') + throw new Error(`Missing logLevelMapping for type ${type}`); Object.defineProperty(this, type, { value: (msg: string, o: WriteOptions) => this.#transport(msg, { ...o, type }) }); } - this.#_guard = opts.guard || Defaults.ClientOptions.guard as string; - this.#_logLevel = opts.logLevel ?? Defaults.ClientOptions.logLevel as number; - this.#_logLevelMapping = { ...Defaults.ClientOptions.logLevelMapping, ...opts.logLevelMapping }; } diff --git a/src/MasterLogger.ts b/src/MasterLogger.ts index 9f3dba9..a412560 100644 --- a/src/MasterLogger.ts +++ b/src/MasterLogger.ts @@ -55,7 +55,6 @@ class MasterLogger implements Logger constructor (config = Defaults.MasterOptions) { - const { directory, customTypes = [], customStreams = [], customTypeMapping, customColours, guard, fileRotationFreq, logLevel, logLevelMapping, @@ -82,6 +81,8 @@ class MasterLogger implements Logger this.#types = [ ...customTypes, ...Defaults.Types ]; for (const type of this.#types) { + if (typeof this.#_logLevelMapping[type] === 'undefined') + throw new Error(`Missing logLevelMapping for type ${type}`); Object.defineProperty(this, type, { value: (msg: string, opts: WriteOptions) => this.write(type, msg, opts) }); @@ -206,8 +207,6 @@ class MasterLogger implements Logger write (type = 'info', text: string | object | Error, { subheader = '', shard, broadcast = false }: WriteOptions = {}) { - - type = type.toLowerCase(); let colour = this.#colourFuncs[type]; if (!colour) colour = this.#colourFuncs.info;