Skip to content

Commit

Permalink
feat(APIM-344): use process variable to enable/disable redacting at b…
Browse files Browse the repository at this point in the history
…ootstrap
  • Loading branch information
avaitonis committed Jul 19, 2023
1 parent 4950a04 commit f1c101a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/logging/console-logger-with-redact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class ConsoleLoggerWithRedact extends ConsoleLogger {
this.stringPatternsToRedact = stringPatternsToRedact;
}

// Simplified, because has just single signature, function from ConsoleLogger.
error(message: any, stack?: string, context?: string) {
let cleanMessage = message;
let cleanStack = stack;
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Logger as NestLogger } from '@nestjs/common';
import { NestApplication, NestFactory } from '@nestjs/core';
import { MainModule } from '@ukef/main.module';

Expand All @@ -6,9 +7,9 @@ import { REDACT_STRINGS } from './constants';
import { ConsoleLoggerWithRedact } from './logging/console-logger-with-redact';

const main = async () => {
// ConsoleLoggerWithRedact is used just if NestFactory.create is fails completely.
// Buffered logs are passed to PinoLogger if NestFactory.create is successfull, ConsoleLoggerWithRedact is not used.
const logger = new ConsoleLoggerWithRedact(REDACT_STRINGS);
// If REDACT_LOGS is true use ConsoleLoggerWithRedact. ConsoleLoggerWithRedact is used just if `NestFactory.create` is fails completely.
// If `NestFactory.create` doesn't fail completely, then buffered logs are passed to PinoLogger. NestLogger and ConsoleLoggerWithRedact are not used.
const logger = process.env.REDACT_LOGS !== 'false' ? new ConsoleLoggerWithRedact(REDACT_STRINGS) : new NestLogger();
const nestApp: NestApplication = await NestFactory.create(MainModule, { logger, bufferLogs: true });
const app = new App(nestApp);

Expand Down

0 comments on commit f1c101a

Please sign in to comment.