Skip to content

Commit

Permalink
feat: enabled pretty print logging as a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
JanssenBrm committed May 24, 2024
1 parent ce46c10 commit 0611ea5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
},
Expand Down
7 changes: 7 additions & 0 deletions src/config/schema/config.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export const schema: convict.Schema<AppConfig> = {
env: 'DEBUG',
arg: 'debug',
},
pretty: {
doc: 'Enable pretty logging',
format: 'Boolean',
default: false,
env: 'PRETTY',
arg: 'pretty',
},
},
auth: {
type: {
Expand Down

0 comments on commit 0611ea5

Please sign in to comment.