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
parent 31b0d797f3
commit 0269b5e87a
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

@ -22,7 +22,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';
@ -31,6 +30,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;
@ -72,7 +72,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

@ -20,7 +20,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';
@ -30,6 +29,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;
@ -69,7 +69,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');