From b9ec21d7982a306b62f22f97cbb0b379329dd998 Mon Sep 17 00:00:00 2001 From: Luca Scalzotto Date: Thu, 15 Aug 2024 20:26:16 +0200 Subject: [PATCH] Check if verbose level is enabled --- src/AutoloadModule.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/AutoloadModule.ts b/src/AutoloadModule.ts index f5dc39d..bf3eff1 100644 --- a/src/AutoloadModule.ts +++ b/src/AutoloadModule.ts @@ -14,7 +14,7 @@ export function AutoloadModule( metadata?: ModuleMetadata ): ClassDecorator { return (target) => { - logger.verbose(`Autoloading module: ${dirName}`); + log(`Autoloading module: ${dirName}`); const loaded = loadScripts(dirName); const combinedMeta: ModuleMetadata = { ...metadata, @@ -39,7 +39,7 @@ function loadScripts(dirName: string): LoadResult { }; for (const script of scripts) { - logger.verbose(`Autoloading file: ${script}`); + log(`Autoloading file: ${script}`); // Here we have to use require, to get the exports into a variable. // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -48,12 +48,12 @@ function loadScripts(dirName: string): LoadResult { for (const check of reqVals) { if (typeof check === 'function') { if (isController(check)) { - logger.verbose(`Found controller: ${check.name}`); + log(`Found controller: ${check.name}`); result.controllers.push(check); } if (isProvider(check)) { - logger.verbose(`Found provider: ${check.name}`); + log(`Found provider: ${check.name}`); result.providers.push(check); } } @@ -63,6 +63,12 @@ function loadScripts(dirName: string): LoadResult { return result; } +function log(message: string): void { + if (Logger.isLevelEnabled('verbose')) { + logger.verbose(message); + } +} + // For both of these functions, // we specifically want to use the Object type because it accepts almost anything.