From 608279f331f188270cab6fb81a18cde2d87f1c40 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Wed, 30 Oct 2024 13:34:00 +0100 Subject: [PATCH 1/2] BC-8093 - fix env variables and add enum --- .env.default | 2 +- .env.test | 2 +- src/infra/logger/logger.config.ts | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.env.default b/.env.default index 0fe93d7d..5a6b43aa 100644 --- a/.env.default +++ b/.env.default @@ -13,5 +13,5 @@ WS_PORT=3345 TLDRAW__WEBSOCKET_URL=ws://localhost:3345 FEATURE_TLDRAW_ENABLED=true -NEST_LOG_LEVEL=DEBUG +NEST_LOG_LEVEL=debug EXIT_ON_ERROR=true \ No newline at end of file diff --git a/.env.test b/.env.test index 46fe40f2..e66d043b 100644 --- a/.env.test +++ b/.env.test @@ -16,5 +16,5 @@ TLDRAW__ASSETS_MAX_SIZE_BYTES=10485760 TLDRAW__ASSETS_ALLOWED_MIME_TYPES_LIST="image/png,image/jpeg,image/gif,image/svg+xml" FEATURE_TLDRAW_ENABLED=true -NEST_LOG_LEVEL=DEBUG +NEST_LOG_LEVEL=debug EXIT_ON_ERROR=true diff --git a/src/infra/logger/logger.config.ts b/src/infra/logger/logger.config.ts index e44f45fb..162af355 100644 --- a/src/infra/logger/logger.config.ts +++ b/src/infra/logger/logger.config.ts @@ -1,9 +1,20 @@ import { Transform } from 'class-transformer'; -import { IsBoolean, IsString } from 'class-validator'; +import { IsBoolean, IsEnum } from 'class-validator'; + +export enum LoggerLogLevel { + emerg = 'emerg', + alert = 'alert', + crit = 'crit', + error = 'error', + warning = 'warning', + notice = 'notice', + info = 'info', + debug = 'debug', +} export class LoggerConfig { - @IsString() - public NEST_LOG_LEVEL!: string; + @IsEnum(LoggerLogLevel) + public NEST_LOG_LEVEL!: LoggerLogLevel; @IsBoolean() @Transform(({ value }) => value === 'true') From eded2fab9beb9c41d1586add812b9564fbc631d6 Mon Sep 17 00:00:00 2001 From: Constantin Bergatt Date: Wed, 30 Oct 2024 13:39:02 +0100 Subject: [PATCH 2/2] BC-8093 - remove unnecessary interface and fix some linter issues --- src/infra/logger/interfaces/logger.interface.ts | 9 +-------- src/infra/logger/logger.spec.ts | 4 ++-- src/infra/logger/logger.ts | 3 +-- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/infra/logger/interfaces/logger.interface.ts b/src/infra/logger/interfaces/logger.interface.ts index 4f423ca3..46a7d833 100644 --- a/src/infra/logger/interfaces/logger.interface.ts +++ b/src/infra/logger/interfaces/logger.interface.ts @@ -1,12 +1,5 @@ -export type RequestLoggingBody = { +export interface RequestLoggingBody { userId?: string; request: { url: string; method: string; params: unknown; query: unknown }; error: unknown | undefined; -}; - -export interface ILogger { - http(message: RequestLoggingBody, context?: string): void; - log(message: unknown, context?: string): void; - warn(message: unknown, context?: string): void; - debug(message: unknown, context?: string): void; } diff --git a/src/infra/logger/logger.spec.ts b/src/infra/logger/logger.spec.ts index 7e4a640c..a3f0ea30 100644 --- a/src/infra/logger/logger.spec.ts +++ b/src/infra/logger/logger.spec.ts @@ -12,12 +12,12 @@ describe('Logger', () => { let processStdoutWriteSpy: jest.SpyInstance< boolean, [str: string | Uint8Array, encoding?: BufferEncoding | undefined, cb?: ((err?: Error) => void) | undefined], - any + unknown >; let processStderrWriteSpy: jest.SpyInstance< boolean, [str: string | Uint8Array, encoding?: BufferEncoding | undefined, cb?: ((err?: Error) => void) | undefined], - any + unknown >; let winstonLogger: DeepMocked; diff --git a/src/infra/logger/logger.ts b/src/infra/logger/logger.ts index e4a50c9a..76aee069 100644 --- a/src/infra/logger/logger.ts +++ b/src/infra/logger/logger.ts @@ -3,10 +3,9 @@ import { WINSTON_MODULE_PROVIDER } from 'nest-winston'; import * as util from 'util'; import * as winston from 'winston'; import { RequestLoggingBody } from './interfaces/index.js'; -import { ILogger } from './interfaces/logger.interface.js'; @Injectable({ scope: Scope.TRANSIENT }) -export class Logger implements ILogger { +export class Logger { /** * This Logger Service can be injected into every Class, * use setContext() with CustomProviderClass.name that will be added to every log.