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(
|
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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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}`
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user