fix: add root parameter to remove scope arrow when logger is not in root

This commit is contained in:
Shinwoo PARK 2023-12-15 01:48:35 +09:00
parent ea16156f6e
commit 29c1235983
2 changed files with 10 additions and 4 deletions

View File

@ -142,12 +142,14 @@ function overrideBuild<F extends Array<any>, R>(
) { ) {
args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger( args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger(
baseLogger, baseLogger,
key key,
true
); );
} else { } else {
args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger( args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger(
args[metadatas.scopedLoggerInjectableParam], args[metadatas.scopedLoggerInjectableParam],
key key,
false
); );
} }

View File

@ -3,10 +3,12 @@ import { Logger } from "@nestjs/common";
type LogLevel = "debug" | "log" | "warn" | "verbose" | "error" | "fatal"; type LogLevel = "debug" | "log" | "warn" | "verbose" | "error" | "fatal";
export class ScopedLogger extends Logger { export class ScopedLogger extends Logger {
scopeId?: string;
constructor( constructor(
private logger: Logger, private logger: Logger,
private scope: string, private scope: string,
private scopeId?: string private root: boolean = false
) { ) {
super(); super();
} }
@ -18,7 +20,9 @@ export class ScopedLogger extends Logger {
private scopedLog(method: LogLevel) { private scopedLog(method: LogLevel) {
return (message: string) => { return (message: string) => {
this.logger[method]( this.logger[method](
`-> ${this.scope}${this.scopeId ? `(${this.scopeId})` : ""}: ${message}` `${this.root ? "" : "-> "}${this.scope}${
this.scopeId ? `(${this.scopeId})` : ""
}: ${message}`
); );
}; };
} }