feat: add getRequestLogger util function for global middleware function

This commit is contained in:
Shinwoo PARK 2025-03-20 18:16:50 +09:00
parent 06c373f858
commit 4c0a28251b
2 changed files with 10 additions and 1 deletions

View File

@ -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<F extends Array<any>, R>(
type: 'route',

9
src/utils.ts Normal file
View File

@ -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])
}