Skip to content

Commit

Permalink
feat(logging): add ability to pass set interceptor params in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
amarlankri committed Nov 9, 2023
1 parent 951791e commit 1548918
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
19 changes: 6 additions & 13 deletions packages/logging-interceptor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ import { LoggingInterceptor } from '@algoan/nestjs-logging-interceptor';
providers: [
{
provide: APP_INTERCEPTOR,
useFactory: () => {
const interceptor: LoggingInterceptor = new LoggingInterceptor();
interceptor.setUserPrefix('ExampleApp');

return interceptor;
},
useFactory: () => new LoggingInterceptor({ userPrefix: 'ExampleApp'}),
},
],
})
Expand Down Expand Up @@ -233,13 +228,11 @@ import { LoggingInterceptor } from '@algoan/nestjs-logging-interceptor';
providers: [
{
provide: APP_INTERCEPTOR,
useFactory: () => {
const interceptor: LoggingInterceptor = new LoggingInterceptor();
interceptor.setDisabledMasking(true); // Ignore masking options in the entire applications
interceptor.setMaskingPlaceholder("hidden"); // Replace the default placeholder '****' by a custom one

return interceptor;
},
useFactory: () =>
new LoggingInterceptor({
disableMasking: true, // Ignore masking options in the entire applications
maskingPlaceholder: 'hidden', // Replace the default placeholder '****' by a custom one
}),
},
],
})
Expand Down
12 changes: 9 additions & 3 deletions packages/logging-interceptor/src/logging.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ import { LogOptions, METHOD_LOG_METADATA } from './log.decorator';
export class LoggingInterceptor implements NestInterceptor {
private readonly ctxPrefix: string = LoggingInterceptor.name;
private readonly logger: Logger = new Logger(this.ctxPrefix);
private userPrefix: string = '';
private disableMasking: boolean = false;
private maskingPlaceholder: string | undefined = '****';
private userPrefix: string;
private disableMasking: boolean;
private maskingPlaceholder: string | undefined;

constructor(options?: { userPrefix?: string; disableMasking?: boolean; maskingPlaceholder?: string }) {
this.userPrefix = options?.userPrefix ?? '';
this.disableMasking = options?.disableMasking ?? false;
this.maskingPlaceholder = options?.maskingPlaceholder ?? '****';
}

/**
* User prefix setter
Expand Down

0 comments on commit 1548918

Please sign in to comment.