From 0611ea514d7c671e282185fa98df4c998caebaf7 Mon Sep 17 00:00:00 2001 From: bramjanssen Date: Fri, 24 May 2024 09:35:51 +0200 Subject: [PATCH] feat: enabled pretty print logging as a parameter --- src/app.module.ts | 21 +++++++++++---------- src/config/schema/config.schema.ts | 7 +++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/app.module.ts b/src/app.module.ts index baaeaa6..0fe0609 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -21,22 +21,23 @@ import { v4 as uuidv4 } from 'uuid'; inject: [ConfigService], useFactory: async (config: ConfigService) => { const level = config.get('general.debug') ? 'debug' : 'warn'; - return { level, pinoHttp: { level, genReqId: (request) => request.headers['x-correlation-id'] || uuidv4(), - transport: { - target: 'pino-pretty', - options: { - colorize: false, - messageFormat: `{req.id} - {req.method} {req.url} {res.statusCode} - {if context}({context}){end} {msg}{message}`, - hideObject: true, - translateTime: 'SYS:standard', - }, - }, + transport: config.get('general.pretty') + ? { + target: 'pino-pretty', + options: { + colorize: false, + messageFormat: `{req.id} - {req.method} {req.url} {res.statusCode} - {if context}({context}){end} {msg}{message}`, + hideObject: true, + translateTime: 'SYS:standard', + }, + } + : undefined, }, }; }, diff --git a/src/config/schema/config.schema.ts b/src/config/schema/config.schema.ts index a742f9f..26eadb2 100644 --- a/src/config/schema/config.schema.ts +++ b/src/config/schema/config.schema.ts @@ -21,6 +21,13 @@ export const schema: convict.Schema = { env: 'DEBUG', arg: 'debug', }, + pretty: { + doc: 'Enable pretty logging', + format: 'Boolean', + default: false, + env: 'PRETTY', + arg: 'pretty', + }, }, auth: { type: {