Logging: Remove NestConsoleLoggerService

This is not necessary anymore, because we can inject ConsoleLoggerService directly.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-04-02 19:08:30 +02:00 committed by David Mehren
parent 8dd3a3d7dd
commit 697ca823d5
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
5 changed files with 12 additions and 50 deletions

View file

@ -6,10 +6,9 @@
import { Module } from '@nestjs/common';
import { ConsoleLoggerService } from './console-logger.service';
import { NestConsoleLoggerService } from './nest-console-logger.service';
@Module({
providers: [ConsoleLoggerService, NestConsoleLoggerService],
exports: [ConsoleLoggerService, NestConsoleLoggerService],
providers: [ConsoleLoggerService],
exports: [ConsoleLoggerService],
})
export class LoggerModule {}

View file

@ -1,39 +0,0 @@
/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Injectable, LoggerService } from '@nestjs/common';
import { ConsoleLoggerService } from './console-logger.service';
Injectable();
export class NestConsoleLoggerService implements LoggerService {
private consoleLoggerService = new ConsoleLoggerService();
debug(message: unknown, context?: string): void {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.debug(message);
}
error(message: unknown, trace?: string, context?: string): void {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.error(message, trace);
}
log(message: unknown, context?: string): void {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.log(message);
}
verbose(message: unknown, context?: string): void {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.verbose(message);
}
warn(message: unknown, context?: string): void {
this.consoleLoggerService.setContext(context);
this.consoleLoggerService.warn(message);
}
}

View file

@ -4,20 +4,22 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { ValidationPipe } from '@nestjs/common';
import { LogLevel, ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
import { AppConfig } from './config/app.config';
import { MediaConfig } from './config/media.config';
import { NestConsoleLoggerService } from './logger/nest-console-logger.service';
import { setupPrivateApiDocs, setupPublicApiDocs } from './utils/swagger';
import { BackendType } from './media/backends/backend-type.enum';
import { ConsoleLoggerService } from './logger/console-logger.service';
async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
const logger = await app.resolve(NestConsoleLoggerService);
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
logger: ['error', 'warn', 'log'] as LogLevel[],
});
const logger = await app.resolve(ConsoleLoggerService);
logger.log('Switching logger', 'AppBootstrap');
app.useLogger(logger);
const configService = app.get(ConfigService);

View file

@ -17,7 +17,6 @@ import customizationConfigMock from '../../src/config/mock/customization.config.
import externalConfigMock from '../../src/config/mock/external-services.config.mock';
import { GroupsModule } from '../../src/groups/groups.module';
import { LoggerModule } from '../../src/logger/logger.module';
import { NestConsoleLoggerService } from '../../src/logger/nest-console-logger.service';
import { MediaModule } from '../../src/media/media.module';
import { NotesModule } from '../../src/notes/notes.module';
import { NotesService } from '../../src/notes/notes.service';
@ -26,6 +25,7 @@ import { AuthModule } from '../../src/auth/auth.module';
import { join } from 'path';
import { PrivateApiModule } from '../../src/api/private/private-api.module';
import { UsersService } from '../../src/users/users.service';
import { ConsoleLoggerService } from '../../src/logger/console-logger.service';
describe('Media', () => {
let app: NestExpressApplication;
@ -67,7 +67,7 @@ describe('Media', () => {
prefix: '/uploads',
});
await app.init();
const logger = await app.resolve(NestConsoleLoggerService);
const logger = await app.resolve(ConsoleLoggerService);
logger.log('Switching logger', 'AppBootstrap');
app.useLogger(logger);
const notesService: NotesService = moduleRef.get('NotesService');

View file

@ -15,7 +15,6 @@ import mediaConfigMock from '../../src/config/mock/media.config.mock';
import appConfigMock from '../../src/config/mock/app.config.mock';
import { GroupsModule } from '../../src/groups/groups.module';
import { LoggerModule } from '../../src/logger/logger.module';
import { NestConsoleLoggerService } from '../../src/logger/nest-console-logger.service';
import { MediaModule } from '../../src/media/media.module';
import { MediaService } from '../../src/media/media.service';
import { NotesModule } from '../../src/notes/notes.module';
@ -25,6 +24,7 @@ import { AuthModule } from '../../src/auth/auth.module';
import { TokenAuthGuard } from '../../src/auth/token-auth.guard';
import { MockAuthGuard } from '../../src/auth/mock-auth.guard';
import { join } from 'path';
import { ConsoleLoggerService } from '../../src/logger/console-logger.service';
describe('Media', () => {
let app: NestExpressApplication;
@ -64,7 +64,7 @@ describe('Media', () => {
prefix: '/uploads',
});
await app.init();
const logger = await app.resolve(NestConsoleLoggerService);
const logger = await app.resolve(ConsoleLoggerService);
logger.log('Switching logger', 'AppBootstrap');
app.useLogger(logger);
const notesService: NotesService = moduleRef.get('NotesService');