Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/docs/04_api/02_module-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
24 changes: 15 additions & 9 deletions packages/core/src/lib/cls-module/cls-root.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/lib/cls.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down