diff --git a/src/logger/logger.module.ts b/src/logger/logger.module.ts index dffa5538d..c95758c8f 100644 --- a/src/logger/logger.module.ts +++ b/src/logger/logger.module.ts @@ -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 {} diff --git a/src/logger/nest-console-logger.service.ts b/src/logger/nest-console-logger.service.ts deleted file mode 100644 index 2fe5b62a4..000000000 --- a/src/logger/nest-console-logger.service.ts +++ /dev/null @@ -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); - } -} diff --git a/src/main.ts b/src/main.ts index 98555016c..7b5cf6e3f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 { - const app = await NestFactory.create(AppModule); - const logger = await app.resolve(NestConsoleLoggerService); + const app = await NestFactory.create(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); diff --git a/test/private-api/media.e2e-spec.ts b/test/private-api/media.e2e-spec.ts index a7da82323..7bda9c2bb 100644 --- a/test/private-api/media.e2e-spec.ts +++ b/test/private-api/media.e2e-spec.ts @@ -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'); diff --git a/test/public-api/media.e2e-spec.ts b/test/public-api/media.e2e-spec.ts index 7e21216f2..01cd708bf 100644 --- a/test/public-api/media.e2e-spec.ts +++ b/test/public-api/media.e2e-spec.ts @@ -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');