Skip to content

Commit 2f6834d

Browse files
committed
feat(core): disable debug
1 parent 77f8609 commit 2f6834d

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The `ClsModule.forRoot()` method takes the following **`ClsModuleOptions`**:
1515

1616
- **_`global?:`_**`boolean`\*\* (default _`false`_)
1717
Whether to make the module global, so you do not have to import `ClsModule.forFeature()` in other modules.
18+
- **_`disableDebug?:`_**`boolean`\*\* (default _`false`_)
19+
Whether disable debugging in the module
1820

1921
- **_`proxyProviders?:`_**`Type[]`
2022
Array of [Proxy Providers](../03_features-and-use-cases/06_proxy-providers.md) that should be registered in the root module. Currently only accepts sync class Proxy providers, use `ClsModule.forFeatureAsync()` for more complex use-cases.

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.disableDebug) {
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.disableDebug) {
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.disableDebug) {
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ export class ClsModuleOptions {
1111
*/
1212
global? = false;
1313

14+
/**
15+
* whether to disable debugging in the module
16+
*/
17+
disableDebug? = false;
18+
1419
/**
1520
* An object with additional options for the `ClsMiddleware`
1621
*/
@@ -113,6 +118,11 @@ export class ClsMiddlewareOptions extends ClsInitializerCommonOptions {
113118
*/
114119
mount? = false;
115120

121+
/**
122+
* whether to disable debugging in the middleware
123+
*/
124+
disableDebug? = false;
125+
116126
/**
117127
* the function to generate request ids for the CLS context
118128
*/
@@ -155,6 +165,11 @@ export class ClsGuardOptions extends ClsInitializerCommonOptions {
155165
*/
156166
mount? = false;
157167

168+
/**
169+
* whether to disable debugging in the guard
170+
*/
171+
disableDebug? = false;
172+
158173
/**
159174
* the function to generate request ids inside the guard
160175
*/
@@ -187,6 +202,11 @@ export class ClsInterceptorOptions extends ClsInitializerCommonOptions {
187202
*/
188203
mount? = false;
189204

205+
/**
206+
* whether to disable debugging in the interceptor
207+
*/
208+
disableDebug? = false;
209+
190210
/**
191211
* the function to generate request ids inside the interceptor
192212
*/

0 commit comments

Comments
 (0)