diff --git a/src/logged.ts b/src/logged.ts index 247d000..f36217b 100644 --- a/src/logged.ts +++ b/src/logged.ts @@ -184,7 +184,7 @@ function createCallLogIdentifyMessage(message: 'HIT' | 'RETURNED' | 'ERROR', typ return `${message} ${callLogIdentifyMessageDictionary[type]}`; } -const REQUEST_LOG_ID = '__nestlogged_request_log_id__'; +export const REQUEST_LOG_ID = '__nestlogged_request_log_id__'; function overrideBuild, R>( type: 'route', diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..783ccd9 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,9 @@ +import { Logger } from "@nestjs/common"; +import { ScopedLogger } from "./logger"; +import { REQUEST_LOG_ID } from "./logged"; + +const logger = new Logger(); + +export function getRequestLogger(functionName: string, req: any) { + return new ScopedLogger(logger, [functionName], req[REQUEST_LOG_ID]) +} \ No newline at end of file