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