fix: add root parameter to remove scope arrow when logger is not in root
This commit is contained in:
parent
ea16156f6e
commit
29c1235983
@ -142,12 +142,14 @@ function overrideBuild<F extends Array<any>, R>(
|
||||
) {
|
||||
args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger(
|
||||
baseLogger,
|
||||
key
|
||||
key,
|
||||
true
|
||||
);
|
||||
} else {
|
||||
args[metadatas.scopedLoggerInjectableParam] = new ScopedLogger(
|
||||
args[metadatas.scopedLoggerInjectableParam],
|
||||
key
|
||||
key,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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}`
|
||||
);
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user