Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-8093 - Check logging implementation (Part 2) #28

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading