diff --git a/src/logged.ts b/src/logged.ts index f1f3f72..9774e07 100644 --- a/src/logged.ts +++ b/src/logged.ts @@ -185,6 +185,8 @@ function createCallLogIdentifyMessage(type: BuildType, key?: string, route?: str return callLogIdentifyMessageDictionary[type]; } +const REQUEST_LOG_ID = '__nestlogged_request_log_id__'; + function overrideBuild, R>( type: 'route', originalFunction: (...args: F) => R, @@ -235,8 +237,12 @@ function overrideBuild, R>( if (ctx.getType() !== 'http') { injectedLogger.error('Cannot inject logger: Request type is not http'); } else { - const req = ctx.switchToHttp().getRequest(); - // TODO HERE + let req = ctx.switchToHttp().getRequest(); + if (req[REQUEST_LOG_ID] === undefined) { + req[REQUEST_LOG_ID] = ScopedLogger.createScopeId(); + } else { + // TODO: INHERIT SCOPE ID + } } } else if (type === 'middleware') { // args[0] == Request diff --git a/src/logger.ts b/src/logger.ts index 2ab9f1f..092c70a 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -38,4 +38,7 @@ export class ScopedLogger extends Logger { logger, [scope] ) }; + static createScopeId(): string { + return createId(); + } } \ No newline at end of file