Skip to content

Commit

Permalink
Chore: Update the logger service so that if it is in debug mode the l…
Browse files Browse the repository at this point in the history
…ogs are human readable.
  • Loading branch information
ajimeno04 committed Jun 28, 2024
1 parent edf3d23 commit 9fc68d8
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/logger/logger.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { pino } from 'pino';
import { LoggerOptions, pino } from 'pino';
import { ConfigService } from 'src/config/config.service';

export const STATUS_LOG_INTERVAL = 60000; //TODO move to config
Expand All @@ -16,8 +16,8 @@ export class LoggerService {
this.logger = pino(this.loggerOptions);
}

private loadLoggerOptions(logLevel?: string): pino.LoggerOptions {
return {
private loadLoggerOptions(logLevel?: string): LoggerOptions {
const baseOptions: LoggerOptions = {
level: logLevel ?? 'info',
base: { pid: process.pid }, // Remove default 'hostname' key from logs
redact: [
Expand All @@ -28,6 +28,23 @@ export class LoggerService {
'*.*.*.*.privateKey',
],
};

if (logLevel === 'debug') {
const transport = {
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'SYS:standard',
},
};

return {
...baseOptions,
transport,
};
} else {
return baseOptions;
}
}

fatal(obj: any, msg?: string | undefined, ...args: any[]): void {
Expand Down

0 comments on commit 9fc68d8

Please sign in to comment.