From 29c1235983d89c9124ae51bba4beb9e6a412f72c Mon Sep 17 00:00:00 2001 From: Shinwoo PARK Date: Fri, 15 Dec 2023 01:48:35 +0900 Subject: [PATCH] fix: add root parameter to remove scope arrow when logger is not in root --- src/logged.ts | 6 ++++-- src/logger.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/logged.ts b/src/logged.ts index cbd7acb..1aa97a8 100644 --- a/src/logged.ts +++ b/src/logged.ts @@ -142,12 +142,14 @@ function overrideBuild, R>( ) { args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger( baseLogger, - key + key, + true ); } else { args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger( args[metadatas.scopedLoggerInjectableParam], - key + key, + false ); } diff --git a/src/logger.ts b/src/logger.ts index 0c28a1c..f19bde9 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -3,10 +3,12 @@ import { Logger } from "@nestjs/common"; type LogLevel = "debug" | "log" | "warn" | "verbose" | "error" | "fatal"; export class ScopedLogger extends Logger { + scopeId?: string; + constructor( private logger: Logger, private scope: string, - private scopeId?: string + private root: boolean = false ) { super(); } @@ -18,7 +20,9 @@ export class ScopedLogger extends Logger { private scopedLog(method: LogLevel) { return (message: string) => { this.logger[method]( - `-> ${this.scope}${this.scopeId ? `(${this.scopeId})` : ""}: ${message}` + `${this.root ? "" : "-> "}${this.scope}${ + this.scopeId ? `(${this.scopeId})` : "" + }: ${message}` ); }; }