From 28a1628722ef828111e187224505a0357f3479b4 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Thu, 15 Jul 2021 20:21:42 +0200 Subject: [PATCH] Switch to new buffered logger NestJS 8 allows the logs to buffer on startup, so that all logs run through our custom logger. See also https://docs.nestjs.com/techniques/logger#dependency-injection Signed-off-by: David Mehren --- src/logger/console-logger.service.ts | 10 ++++++++-- src/main.ts | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/logger/console-logger.service.ts b/src/logger/console-logger.service.ts index c87460bce..6640788d1 100644 --- a/src/logger/console-logger.service.ts +++ b/src/logger/console-logger.service.ts @@ -4,7 +4,13 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { Inject, Injectable, Optional, Scope } from '@nestjs/common'; +import { + Inject, + Injectable, + LoggerService, + Optional, + Scope, +} from '@nestjs/common'; import { isObject } from '@nestjs/common/utils/shared.utils'; import clc = require('cli-color'); import DateTimeFormatOptions = Intl.DateTimeFormatOptions; @@ -13,7 +19,7 @@ import { Loglevel } from '../config/loglevel.enum'; import { needToLog } from '../config/utils'; @Injectable({ scope: Scope.TRANSIENT }) -export class ConsoleLoggerService { +export class ConsoleLoggerService implements LoggerService { private classContext: string | undefined; private lastTimestamp: number; diff --git a/src/main.ts b/src/main.ts index d2b75f3a9..45bc1586e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -18,6 +18,7 @@ import { ConsoleLoggerService } from './logger/console-logger.service'; async function bootstrap(): Promise { const app = await NestFactory.create(AppModule, { logger: ['error', 'warn', 'log'] as LogLevel[], + bufferLogs: true, }); const logger = await app.resolve(ConsoleLoggerService); logger.log('Switching logger', 'AppBootstrap');