This commit is contained in:
Shinwoo PARK 2025-03-19 15:30:09 +09:00
parent c74ad2b119
commit 00fd3e33c4
2 changed files with 24 additions and 6 deletions

Binary file not shown.

View File

@ -218,13 +218,31 @@ function overrideBuild<F extends Array<any>, R>(
// Creating ScopedLogger
let injectedLogger: Logger = baseLogger;
if (typeof metadatas.scopedLoggerInjectableParam !== "undefined") {
if (
args.length <= metadatas.scopedLoggerInjectableParam ||
!(args[metadatas.scopedLoggerInjectableParam] instanceof ScopedLogger)
) {
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot(baseLogger, key);
if (type === 'function') {
if (
args.length <= metadatas.scopedLoggerInjectableParam ||
!(args[metadatas.scopedLoggerInjectableParam] instanceof ScopedLogger)
) {
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot(baseLogger, key);
} else {
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromSuper(baseLogger, args[metadatas.scopedLoggerInjectableParam], key);
}
} else {
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromSuper(baseLogger, args[metadatas.scopedLoggerInjectableParam], key);
// special, can access to request object
if (type === 'guard' || type === 'interceptor') {
// args[0] == ExecutionContext
const ctx = (args[0] as ExecutionContext);
if (ctx.getType() !== 'http') {
injectedLogger.error('Cannot inject logger: Request type is not http');
} else {
const req = ctx.switchToHttp().getRequest();
// TODO HERE
}
} else if (type === 'middleware') {
// args[0] == Request
} else if (type === 'route') {
// should use @Req
}
}
injectedLogger = args[metadatas.scopedLoggerInjectableParam];