diff --git a/docs/docs/04_api/02_module-options.md b/docs/docs/04_api/02_module-options.md index 10c90962..d569fdc2 100644 --- a/docs/docs/04_api/02_module-options.md +++ b/docs/docs/04_api/02_module-options.md @@ -75,6 +75,9 @@ All of the **`Cls{Middleware,Guard,Interceptor}Options`** take the following par - **_`mount?:`_**`boolean` (default _`false`_) Whether to automatically mount the middleware/guard/interceptor to every route (not applicable when instantiating them manually) +- **_`debug?:`_**`boolean` (default _`true`_) + Enable logging of debug messages in the middleware/guard/interceptor. + - **_`generateId?:`_**`boolean` (default _`false`_) Whether to automatically generate a request ID. It will be available under the `CLS_ID` key. diff --git a/packages/core/src/lib/cls-module/cls-root.module.ts b/packages/core/src/lib/cls-module/cls-root.module.ts index f849b24f..669c8d83 100644 --- a/packages/core/src/lib/cls-module/cls-root.module.ts +++ b/packages/core/src/lib/cls-module/cls-root.module.ts @@ -61,9 +61,11 @@ export class ClsRootModule implements NestModule, OnModuleInit { if (options.mount) { const adapter = this.adapterHost.httpAdapter; const mountPoint = getMiddlewareMountPoint(adapter); - ClsRootModule.logger.debug( - 'Mounting ClsMiddleware to ' + mountPoint, - ); + if (options.debug) { + ClsRootModule.logger.debug( + 'Mounting ClsMiddleware to ' + mountPoint, + ); + } consumer.apply(ClsMiddleware).forRoutes(mountPoint); } } @@ -215,9 +217,11 @@ export class ClsRootModule implements NestModule, OnModuleInit { private static clsGuardFactory(options: ClsGuardOptions): CanActivate { if (options.mount) { - ClsRootModule.logger.debug( - 'ClsGuard will be automatically mounted', - ); + if (options.debug) { + ClsRootModule.logger.debug( + 'ClsGuard will be automatically mounted', + ); + } return new ClsGuard(options); } return { @@ -229,9 +233,11 @@ export class ClsRootModule implements NestModule, OnModuleInit { options: ClsInterceptorOptions, ): NestInterceptor { if (options.mount) { - ClsRootModule.logger.debug( - 'ClsInterceptor will be automatically mounted', - ); + if (options.debug) { + ClsRootModule.logger.debug( + 'ClsInterceptor will be automatically mounted', + ); + } return new ClsInterceptor(options); } return { diff --git a/packages/core/src/lib/cls.options.ts b/packages/core/src/lib/cls.options.ts index 3d4c8354..a5f0cccf 100644 --- a/packages/core/src/lib/cls.options.ts +++ b/packages/core/src/lib/cls.options.ts @@ -113,6 +113,13 @@ export class ClsMiddlewareOptions extends ClsInitializerCommonOptions { */ mount? = false; + /** + * enable logging of debug messages in the middleware + * + * Default: `true` + */ + debug? = true; + /** * the function to generate request ids for the CLS context */ @@ -155,6 +162,13 @@ export class ClsGuardOptions extends ClsInitializerCommonOptions { */ mount? = false; + /** + * enable logging of debug messages in guard + * + * Default: `true` + */ + debug? = true; + /** * the function to generate request ids inside the guard */ @@ -187,6 +201,13 @@ export class ClsInterceptorOptions extends ClsInitializerCommonOptions { */ mount? = false; + /** + * enable logging of debug messages in the interceptor + * + * Default: `true` + */ + debug? = true; + /** * the function to generate request ids inside the interceptor */