Skip to content

Commit

Permalink
Merge pull request #798 from MTES-MCT/fix-json-production-logs-for-elk
Browse files Browse the repository at this point in the history
Prettify logs in development and leave as JSON in production
  • Loading branch information
Falinor authored Jun 27, 2024
2 parents 5ad19ea + e9b5a89 commit 52553a3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/utils/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pino from 'pino';
import pino, { LoggerOptions as PinoLoggerOptions } from 'pino';
import { LogLevel } from './log-level';

interface LoggerOptions {
Expand All @@ -22,20 +22,23 @@ export interface Logger {

export function createLogger(name: string, opts: LoggerOptions): Logger {
const level = opts.level ?? LogLevel.DEBUG;
const logger = pino({
const developmentOptions: PinoLoggerOptions = {
transport: {
target: 'pino-pretty',
},
target: 'pino-pretty'
}
};
const logger = pino({
...(opts.isProduction ? {} : developmentOptions),
name,
level,
level
});

return {
trace: toPinoLogFn(logger.trace.bind(logger)),
debug: toPinoLogFn(logger.debug.bind(logger)),
info: toPinoLogFn(logger.info.bind(logger)),
warn: toPinoLogFn(logger.warn.bind(logger)),
error: toPinoLogFn(logger.error.bind(logger)),
error: toPinoLogFn(logger.error.bind(logger))
};
}

Expand Down

0 comments on commit 52553a3

Please sign in to comment.