diff --git a/src/lib/BravoClient.ts b/src/lib/BravoClient.ts index 53ca7bc..1d5e2c8 100644 --- a/src/lib/BravoClient.ts +++ b/src/lib/BravoClient.ts @@ -12,6 +12,7 @@ import { stringsMatch, generateRandomString, stringToNumber, + wrapIfNotArray, } from './utility.js'; import { BravoCollection } from './entities/BravoCollection'; import { BravoUser } from '$/lib/entities/BravoUser'; @@ -20,6 +21,7 @@ import { BravoWidget } from '$entities/BravoWidget.js'; import { BravoColumn } from './entities/BravoColumn.js'; import type { ArrayMatchFunction, + OneOrMore, PartialBy, RequiredBy, } from '$/types/Utility.js'; @@ -33,7 +35,7 @@ import type { BravoEntity } from './BravoEntity.js'; import type { FavroApi } from '$types/FavroApi.js'; import { BravoWebhookDefinition } from './entities/BravoWebhook.js'; import { BravoGroup } from '$/types/Bravo.js'; -import { DebugPath, Logger } from './Logger.js'; +import { DebugPath, DebugPathSetting, Logger } from './Logger.js'; export { FavroClientAuth as BravoClientAuth } from './clientLib/FavroClient.js'; @@ -81,8 +83,12 @@ export class BravoClient extends FavroClient { return new BravoResponseEntities(this, entityClass, res); } - enableDebugLogging(debugNamespace: DebugPath) { - Logger.enableDebug(debugNamespace); + /** + * Override any previous debugLogging settings + * with a new set. + */ + enableDebugLogging(debugNamespaces: OneOrMore) { + Logger.enableDebug(wrapIfNotArray(debugNamespaces)); } disableDebugLogging() { diff --git a/src/lib/Logger.ts b/src/lib/Logger.ts index 8679a81..d42d2fb 100644 --- a/src/lib/Logger.ts +++ b/src/lib/Logger.ts @@ -1,7 +1,6 @@ import type { DebugPaths } from '$/types/ObjectPaths.js'; import type { AnyFunction } from '$/types/Utility.js'; import debug from 'debug'; -import { sortPaths } from './utility.js'; const requiredLogLevels = ['log', 'error'] as const; const optionalLogLevels = ['info', 'trace', 'warn', 'dir'] as const; @@ -17,6 +16,7 @@ export type LoggerUtility = { }; export type DebugPath = DebugPaths; +export type DebugPathSetting = DebugPath | `-${DebugPath}`; export class Logger { private static _debuggers: { [namePath: string]: debug.Debugger } = {}; @@ -37,8 +37,8 @@ export class Logger { } as const; } - static enableDebug(debugNamespace: DebugPath) { - debug.enable(debugNamespace); + static enableDebug(debugNamespaces: DebugPathSetting[]) { + debug.enable(debugNamespaces.join(',')); } static disableDebug() { @@ -71,19 +71,14 @@ export class Logger { Logger._utility.error.bind(Logger._utility)(...args); } - static getDebugLogger(path: string, parentPath?: string) { - const fullPath = parentPath ? `${parentPath}:${path}` : path; - this._debuggers[fullPath] ||= debug(fullPath); - this._debuggers[fullPath].log = Logger.log; - this._debuggerPaths.add(fullPath); - return this._debuggers[fullPath]; + static getDebugLogger(path: DebugPath) { + this._debuggers[path] ||= debug(path); + this._debuggers[path].log = Logger.log; + this._debuggerPaths.add(path); + return this._debuggers[path]; } static set loggingUtility(utility: LoggerUtility) { Logger._utility = utility; } - - static get debugPaths() { - return sortPaths([...this._debuggerPaths], ':'); - } } diff --git a/src/types/Utility.ts b/src/types/Utility.ts index 6b5fc26..0c40300 100644 --- a/src/types/Utility.ts +++ b/src/types/Utility.ts @@ -54,7 +54,7 @@ export type ParametersExcludingIndices< export type ParametersExcludingFirst = ParametersExcludingIndices; -export type ValueOrValueArray = T[] | T; +export type OneOrMore = T[] | T; export type ExtractKeysByValue = { [Key in keyof Container]-?: Container[Key] extends Function