diff --git a/.env.sample b/.env.sample index b3f44894..830dd55e 100644 --- a/.env.sample +++ b/.env.sample @@ -3,6 +3,7 @@ PORT= LOG_LEVEL=debug REDACT_LOGS=false +SINGLE_LINE_LOG_FORMAT=true # Swagger SWAGGER_USER= diff --git a/src/config/app.config.test.ts b/src/config/app.config.test.ts index 4197317d..30993c04 100644 --- a/src/config/app.config.test.ts +++ b/src/config/app.config.test.ts @@ -129,6 +129,56 @@ describe('appConfig', () => { }); }); + describe('parsing SINGLE_LINE_LOG_FORMAT', () => { + it('sets singleLineLogFormat to true if SINGLE_LINE_LOG_FORMAT is true', () => { + replaceEnvironmentVariables({ + SINGLE_LINE_LOG_FORMAT: 'true', + }); + + const config = appConfig(); + + expect(config.singleLineLogFormat).toBe(true); + }); + + it('sets singleLineLogFormat to false if SINGLE_LINE_LOG_FORMAT is false', () => { + replaceEnvironmentVariables({ + SINGLE_LINE_LOG_FORMAT: 'false', + }); + + const config = appConfig(); + + expect(config.singleLineLogFormat).toBe(false); + }); + + it('sets singleLineLogFormat to true if SINGLE_LINE_LOG_FORMAT is not specified', () => { + replaceEnvironmentVariables({}); + + const config = appConfig(); + + expect(config.singleLineLogFormat).toBe(true); + }); + + it('sets singleLineLogFormat to true if SINGLE_LINE_LOG_FORMAT is the empty string', () => { + replaceEnvironmentVariables({ + SINGLE_LINE_LOG_FORMAT: '', + }); + + const config = appConfig(); + + expect(config.singleLineLogFormat).toBe(true); + }); + + it('sets singleLineLogFormat to true if SINGLE_LINE_LOG_FORMAT is any string other than true or false', () => { + replaceEnvironmentVariables({ + SINGLE_LINE_LOG_FORMAT: valueGenerator.string(), + }); + + const config = appConfig(); + + expect(config.singleLineLogFormat).toBe(true); + }); + }); + const replaceEnvironmentVariables = (newEnvVariables: Record): void => { process.env = newEnvVariables; }; diff --git a/src/config/app.config.ts b/src/config/app.config.ts index f38e82c5..3c1b69bc 100644 --- a/src/config/app.config.ts +++ b/src/config/app.config.ts @@ -24,5 +24,6 @@ export default registerAs('app', (): Record => { apiKey: process.env.API_KEY, logLevel: process.env.LOG_LEVEL || 'info', redactLogs: process.env.REDACT_LOGS !== 'false', + singleLineLogFormat: process.env.SINGLE_LINE_LOG_FORMAT !== 'false', }; }); diff --git a/src/main.module.ts b/src/main.module.ts index 6fb41e02..afd47d2e 100644 --- a/src/main.module.ts +++ b/src/main.module.ts @@ -29,7 +29,7 @@ import { LoggingInterceptor } from './logging/logging-interceptor.helper'; transport: { target: 'pino-pretty', options: { - singleLine: true, + singleLine: config.get('app.singleLineLogLevel'), }, }, hooks: { diff --git a/test/support/environment-variables.ts b/test/support/environment-variables.ts index cb9e3133..1c9a8d29 100644 --- a/test/support/environment-variables.ts +++ b/test/support/environment-variables.ts @@ -6,6 +6,7 @@ export const ENVIRONMENT_VARIABLES = Object.freeze({ NODE_ENV: 'test', LOG_LEVEL: 'debug', REDACT_LOGS: false, + SINGLE_LINE_LOG_FORMAT: true, SWAGGER_USER: valueGenerator.string(), SWAGGER_PASSWORD: valueGenerator.string(), @@ -22,6 +23,7 @@ export const ENVIRONMENT_VARIABLES = Object.freeze({ export const getEnvironmentVariablesForProcessEnv = (): NodeJS.ProcessEnv => ({ ...ENVIRONMENT_VARIABLES, REDACT_LOGS: ENVIRONMENT_VARIABLES.REDACT_LOGS.toString(), + SINGLE_LINE_LOG_FORMAT: ENVIRONMENT_VARIABLES.SINGLE_LINE_LOG_FORMAT.toString(), APIM_INFORMATICA_MAX_REDIRECTS: ENVIRONMENT_VARIABLES.APIM_INFORMATICA_MAX_REDIRECTS.toString(), APIM_INFORMATICA_TIMEOUT: ENVIRONMENT_VARIABLES.APIM_INFORMATICA_TIMEOUT.toString(), });