feat: make overrideBuild log with class name

This commit is contained in:
Shinwoo PARK 2025-03-27 05:51:56 +09:00
parent cb324c54be
commit e06970a51e

View File

@ -44,6 +44,8 @@ export function overrideBuild<F extends Array<any>, R>(
logged: LoggedMetadata, logged: LoggedMetadata,
route?: string, route?: string,
): (...args: F) => R { ): (...args: F) => R {
const name = _target.name ?? _target.constructor.name;
return function (...args: F): R { return function (...args: F): R {
const baseLogger: Logger = loggerInit(_target); const baseLogger: Logger = loggerInit(_target);
@ -57,13 +59,13 @@ export function overrideBuild<F extends Array<any>, R>(
) { ) {
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot( args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot(
baseLogger, baseLogger,
key, [name, key],
); );
} else { } else {
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromSuper( args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromSuper(
baseLogger, baseLogger,
args[metadatas.scopedLoggerInjectableParam], args[metadatas.scopedLoggerInjectableParam],
key, [name, key],
); );
} }
} else { } else {
@ -82,7 +84,7 @@ export function overrideBuild<F extends Array<any>, R>(
} }
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot( args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot(
baseLogger, baseLogger,
key, [name, key],
req[REQUEST_LOG_ID], req[REQUEST_LOG_ID],
); );
} }
@ -93,7 +95,7 @@ export function overrideBuild<F extends Array<any>, R>(
} }
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot( args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot(
baseLogger, baseLogger,
key, [name, key],
req[REQUEST_LOG_ID], req[REQUEST_LOG_ID],
); );
} else if (type === 'route') { } else if (type === 'route') {
@ -104,7 +106,7 @@ export function overrideBuild<F extends Array<any>, R>(
} }
args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot( args[metadatas.scopedLoggerInjectableParam] = ScopedLogger.fromRoot(
baseLogger, baseLogger,
key, [name, key],
req[REQUEST_LOG_ID], req[REQUEST_LOG_ID],
); );
} }
@ -129,8 +131,8 @@ export function overrideBuild<F extends Array<any>, R>(
type === 'guard' || type === 'guard' ||
type === 'interceptor' || type === 'interceptor' ||
type === 'route' type === 'route'
? createCallLogIdentifyMessage('HIT', type, key, route) ? createCallLogIdentifyMessage('HIT', type, `${name}.${key}`, route)
: createCallLogIdentifyMessage('HIT', type, key); : createCallLogIdentifyMessage('HIT', type, `${name}.${key}`);
injectedLogger[logged.options.callLogLevel]( injectedLogger[logged.options.callLogLevel](
`${callLogIdentifyMessage} ${ `${callLogIdentifyMessage} ${
metadatas.loggedParams && metadatas.loggedParams.length > 0 metadatas.loggedParams && metadatas.loggedParams.length > 0
@ -184,7 +186,7 @@ export function overrideBuild<F extends Array<any>, R>(
: ''; : '';
injectedLogger[logged.options.returnLogLevel]( injectedLogger[logged.options.returnLogLevel](
`${createCallLogIdentifyMessage('RETURNED', type, key, route)} ${resultLogged}`, `${createCallLogIdentifyMessage('RETURNED', type, `${name}.${key}`, route)} ${resultLogged}`,
); );
return r; return r;
}); });
@ -212,7 +214,7 @@ export function overrideBuild<F extends Array<any>, R>(
: ''; : '';
injectedLogger[logged.options.returnLogLevel]( injectedLogger[logged.options.returnLogLevel](
`${createCallLogIdentifyMessage('RETURNED', type, key, route)} ${resultLogged}`, `${createCallLogIdentifyMessage('RETURNED', type, `${name}.${key}`, route)} ${resultLogged}`,
); );
return r; return r;
} }
@ -223,7 +225,7 @@ export function overrideBuild<F extends Array<any>, R>(
// Error Log // Error Log
if (logged.options.errorLogLevel !== 'skip') { if (logged.options.errorLogLevel !== 'skip') {
injectedLogger[logged.options.errorLogLevel]( injectedLogger[logged.options.errorLogLevel](
`${createCallLogIdentifyMessage('ERROR', type, key, route)} ${e}`, `${createCallLogIdentifyMessage('ERROR', type, `${name}.${key}`, route)} ${e}`,
); );
} }
throw e; throw e;