Skip to content

Commit

Permalink
Merge pull request #848 from amarlankri/logging/feat/add-getter
Browse files Browse the repository at this point in the history
[FEAT] Add getter functions for logging interceptor fields
  • Loading branch information
g-ongenae authored Feb 16, 2024
2 parents 0ceeaa3 + 606b596 commit 471ff54
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/logging-interceptor/src/logging.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export class LoggingInterceptor implements NestInterceptor {
this.mask = options?.mask;
}

/**
* Return the user prefix
*/
public getUserPrefix(): string {
return this.userPrefix;
}

/**
* User prefix setter
* ex. [MyPrefix - LoggingInterceptor - 200 - GET - /]
Expand All @@ -84,6 +91,13 @@ export class LoggingInterceptor implements NestInterceptor {
this.userPrefix = `${prefix} - `;
}

/**
* Return the disable masking flag
*/
public getDisabledMasking(): boolean {
return this.disableMasking;
}

/**
* Set the disable masking flag
* @param disableMasking
Expand All @@ -92,6 +106,13 @@ export class LoggingInterceptor implements NestInterceptor {
this.disableMasking = disableMasking;
}

/**
* Return the masking placeholder
*/
public getMaskingPlaceholder(): string | undefined {
return this.maskingPlaceholder;
}

/**
* Set the masking placeholder
* @param placeholder
Expand All @@ -100,6 +121,13 @@ export class LoggingInterceptor implements NestInterceptor {
this.maskingPlaceholder = placeholder;
}

/**
* Return the masking options
*/
public getMask(): LoggingInterceptorMaskingOptions | undefined {
return this.mask;
}

/**
* Set the masking options
* @param mask
Expand Down
33 changes: 33 additions & 0 deletions packages/logging-interceptor/test/logging.interceptor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,39 @@ describe('Logging interceptor', () => {
});
});

describe('LoggingInterceptor - Getters and setters', () => {
it('allows to set and get a user prefix', async () => {
const interceptor = new LoggingInterceptor();
const prefix = 'MyPrefix';
interceptor.setUserPrefix(prefix);
expect(interceptor.getUserPrefix()).toEqual(`${prefix} - `);
});

it('allows to set and get the disable masking flag', async () => {
const interceptor = new LoggingInterceptor();
interceptor.setDisableMasking(true);
expect(interceptor.getDisabledMasking()).toEqual(true);
});

it('allows to set and get the masking placeholder', async () => {
const interceptor = new LoggingInterceptor();
const placeholder = '****';
interceptor.setMaskingPlaceholder(placeholder);
expect(interceptor.getMaskingPlaceholder()).toEqual(placeholder);
});

it('allows to set and get the masking options', async () => {
const interceptor = new LoggingInterceptor();
const mask = {
requestHeader: {
authorization: true,
},
};
interceptor.setMask(mask);
expect(interceptor.getMask()).toEqual(mask);
});
});

describe('LoggingInterceptor - Masking options', () => {
const placeholder = '****';

Expand Down

0 comments on commit 471ff54

Please sign in to comment.