fix: log write시 인코딩 깨지는 문제 해결
This commit is contained in:
parent
c92c1c2470
commit
94da4f3452
@ -94,13 +94,24 @@ const dailyLogger = new DailyLogger()
|
|||||||
export const writeApiLog = async (request: NextRequest, responseStatus: number): Promise<void> => {
|
export const writeApiLog = async (request: NextRequest, responseStatus: number): Promise<void> => {
|
||||||
if (!isProduction) return
|
if (!isProduction) return
|
||||||
|
|
||||||
|
let bodyString: string | undefined
|
||||||
|
if (
|
||||||
|
request.method === 'POST' &&
|
||||||
|
(request.headers.get('content-type') === 'multipart/form-data' || request.headers.get('content-type') === 'application/x-www-form-urlencoded')
|
||||||
|
) {
|
||||||
|
const formData = await request.formData()
|
||||||
|
bodyString = JSON.stringify(Object.fromEntries(formData))
|
||||||
|
} else {
|
||||||
|
bodyString = await request.text()
|
||||||
|
}
|
||||||
|
|
||||||
const logData: ApiLogData = {
|
const logData: ApiLogData = {
|
||||||
responseStatus: responseStatus,
|
responseStatus: responseStatus,
|
||||||
method: request.method,
|
method: request.method,
|
||||||
url: request.url,
|
url: request.url,
|
||||||
// headers: Object.fromEntries(request.headers),
|
// headers: Object.fromEntries(request.headers),
|
||||||
query: Object.fromEntries(new URL(request.url).searchParams),
|
query: Object.fromEntries(new URL(request.url).searchParams),
|
||||||
body: request.body ? await request.text() : undefined,
|
body: bodyString,
|
||||||
}
|
}
|
||||||
dailyLogger.info(logData, 'API Request')
|
dailyLogger.info(logData, 'API Request')
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user