Skip to content

Commit

Permalink
BC-8093 - Check logging implementation (Part 2) (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergatco authored Oct 30, 2024
1 parent 59dc128 commit e96f9a5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 1 addition & 8 deletions src/infra/logger/interfaces/logger.interface.ts
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 14 additions & 3 deletions src/infra/logger/logger.config.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/infra/logger/logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WinstonLogger>;

Expand Down
3 changes: 1 addition & 2 deletions src/infra/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e96f9a5

Please sign in to comment.