Add logger module and custom logger implementation

ConsoleLoggerService is based on the default Nest LoggerService, but adds the ability to give context about the function that is logging something. It also removes the `[Nest]` string and the PID at the beginning of each log line.

NestConsoleLoggerService is a wrapper around ConsoleLoggerService and makes it possible to use our implementation as a default Nest LoggerService

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2020-09-27 21:41:02 +02:00
parent d07d8fe278
commit 1a2959f6dc
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 161 additions and 0 deletions

View file

@ -0,0 +1,33 @@
import { Injectable, LoggerService } from '@nestjs/common';
import { ConsoleLoggerService } from './console-logger.service';
Injectable();
export class NestConsoleLoggerService implements LoggerService {
private consoleLoggerService = new ConsoleLoggerService();
debug(message: any, context?: string): any {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.debug(message);
}
error(message: any, trace?: string, context?: string): any {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.error(message);
}
log(message: any, context?: string): any {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.log(message);
}
verbose(message: any, context?: string): any {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.verbose(message);
}
warn(message: any, context?: string): any {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.warn(message);
}
}