Skip to content

Commit abbdf1d

Browse files
committed
feat(core): add debug ability
1 parent 77f8609 commit abbdf1d

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

docs/docs/04_api/02_module-options.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ All of the **`Cls{Middleware,Guard,Interceptor}Options`** take the following par
7575
- **_`mount?:`_**`boolean` (default _`false`_)
7676
Whether to automatically mount the middleware/guard/interceptor to every route (not applicable when instantiating them manually)
7777

78+
- **_`debug?:`_**`boolean` (default _`true`_)
79+
Whether to enable debugging in the middleware/guard/interceptor.
80+
7881
- **_`generateId?:`_**`boolean` (default _`false`_)
7982
Whether to automatically generate a request ID. It will be available under the `CLS_ID` key.
8083

packages/core/src/lib/cls-module/cls-root.module.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ export class ClsRootModule implements NestModule, OnModuleInit {
6161
if (options.mount) {
6262
const adapter = this.adapterHost.httpAdapter;
6363
const mountPoint = getMiddlewareMountPoint(adapter);
64-
ClsRootModule.logger.debug(
65-
'Mounting ClsMiddleware to ' + mountPoint,
66-
);
64+
if (options.debug) {
65+
ClsRootModule.logger.debug(
66+
'Mounting ClsMiddleware to ' + mountPoint,
67+
);
68+
}
6769
consumer.apply(ClsMiddleware).forRoutes(mountPoint);
6870
}
6971
}
@@ -215,9 +217,11 @@ export class ClsRootModule implements NestModule, OnModuleInit {
215217

216218
private static clsGuardFactory(options: ClsGuardOptions): CanActivate {
217219
if (options.mount) {
218-
ClsRootModule.logger.debug(
219-
'ClsGuard will be automatically mounted',
220-
);
220+
if (options.debug) {
221+
ClsRootModule.logger.debug(
222+
'ClsGuard will be automatically mounted',
223+
);
224+
}
221225
return new ClsGuard(options);
222226
}
223227
return {
@@ -229,9 +233,11 @@ export class ClsRootModule implements NestModule, OnModuleInit {
229233
options: ClsInterceptorOptions,
230234
): NestInterceptor {
231235
if (options.mount) {
232-
ClsRootModule.logger.debug(
233-
'ClsInterceptor will be automatically mounted',
234-
);
236+
if (options.debug) {
237+
ClsRootModule.logger.debug(
238+
'ClsInterceptor will be automatically mounted',
239+
);
240+
}
235241
return new ClsInterceptor(options);
236242
}
237243
return {

packages/core/src/lib/cls.options.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ export class ClsMiddlewareOptions extends ClsInitializerCommonOptions {
113113
*/
114114
mount? = false;
115115

116+
/**
117+
* whether to enable debugging in the middleware
118+
*/
119+
debug? = true;
120+
116121
/**
117122
* the function to generate request ids for the CLS context
118123
*/
@@ -155,6 +160,11 @@ export class ClsGuardOptions extends ClsInitializerCommonOptions {
155160
*/
156161
mount? = false;
157162

163+
/**
164+
* whether to enable debugging in the guard
165+
*/
166+
debug? = true;
167+
158168
/**
159169
* the function to generate request ids inside the guard
160170
*/
@@ -187,6 +197,11 @@ export class ClsInterceptorOptions extends ClsInitializerCommonOptions {
187197
*/
188198
mount? = false;
189199

200+
/**
201+
* whether to enable debugging in the interceptor
202+
*/
203+
debug? = true;
204+
190205
/**
191206
* the function to generate request ids inside the interceptor
192207
*/

0 commit comments

Comments
 (0)