feat: 테스트 환경에서 백엔드로 나가는 모든 요청을 서버 로그에
로그가 콘텐츠 쓰기에만 있어 만화 등록 같은 요청은 형태를 확인할 수 없었다. backend-fetch 단일 진입점(일반·스트림 다운로드·스트림 업로드)으로 내려 메서드, 쿼리 포함 전체 URL, 본문(JSON은 Swagger에 붙여 넣을 수 있는 모양, form은 인코딩 문자열, multipart는 파일명·크기)을 전부 찍는다. 운영에서는 찍지 않는다. 콘텐츠 쪽 성공 로그는 중복이라 실패 전용으로 되돌린다. Co-Authored-By: Claude Opus 5
@26520a2b486dc5a2e9c1ac2e75ae780b5ba6e364
--- lib/data/repositories/content-repository.ts
+++ lib/data/repositories/content-repository.ts
... | ... | @@ -347,29 +347,18 @@ |
| 347 | 347 |
} |
| 348 | 348 |
|
| 349 | 349 |
/** |
| 350 |
- * 보낸 것을 서버 콘솔에 그대로 남긴다. |
|
| 351 |
- * |
|
| 352 |
- * 브라우저 네트워크 탭에는 이 요청이 **뜨지 않는다** — 화면은 Server Action을 부르고 백엔드 |
|
| 353 |
- * 호출은 서버에서 일어난다(BFF). 그래서 개발 중에는 성공·실패를 가리지 않고 찍고, 운영에서는 |
|
| 354 |
- * 실패만 남긴다. JSON은 Swagger의 Request body에 그대로 붙여 넣을 수 있는 모양이다. |
|
| 350 |
+ * 실패한 쓰기의 사유와 보낸 본문을 남긴다. 요청 자체는 테스트 환경에서 backend-fetch가 |
|
| 351 |
+ * 전부 찍으므로(중앙 로거) 여기는 실패만 맡는다 — 운영에서도 원인 추적에 이게 유일한 단서다. |
|
| 355 | 352 |
*/ |
| 356 |
-function logWrite( |
|
| 353 |
+function logWriteFailure( |
|
| 357 | 354 |
method: string, |
| 358 | 355 |
path: string, |
| 359 | 356 |
body: unknown, |
| 360 | 357 |
form: Record<string, string | number | undefined> | undefined, |
| 361 |
- failure: { code: number; message: string } | null
|
|
| 358 |
+ failure: { code: number; message: string }
|
|
| 362 | 359 |
): void {
|
| 363 |
- if (failure === null && process.env.NODE_ENV === 'production') {
|
|
| 364 |
- return; |
|
| 365 |
- } |
|
| 366 |
- |
|
| 367 |
- const head = failure |
|
| 368 |
- ? `[contents] ${method} ${path} 실패 (code ${failure.code}: ${failure.message})`
|
|
| 369 |
- : `[contents] ${method} ${path}`;
|
|
| 370 |
- |
|
| 371 | 360 |
const lines = [ |
| 372 |
- head, |
|
| 361 |
+ `[contents] ${method} ${path} 실패 (code ${failure.code}: ${failure.message})`,
|
|
| 373 | 362 |
body === undefined ? null : `body(JSON):\n${JSON.stringify(body, null, 2)}`,
|
| 374 | 363 |
form === undefined |
| 375 | 364 |
? null |
... | ... | @@ -380,11 +369,7 @@ |
| 380 | 369 |
).toString()}`, |
| 381 | 370 |
].filter(Boolean); |
| 382 | 371 |
|
| 383 |
- if (failure) {
|
|
| 384 |
- console.error(lines.join('\n'));
|
|
| 385 |
- } else {
|
|
| 386 |
- console.info(lines.join('\n'));
|
|
| 387 |
- } |
|
| 372 |
+ console.error(lines.join('\n'));
|
|
| 388 | 373 |
} |
| 389 | 374 |
|
| 390 | 375 |
async function sendWrite( |
... | ... | @@ -405,9 +390,8 @@ |
| 405 | 390 |
canHaveEmptyBody: true, |
| 406 | 391 |
}); |
| 407 | 392 |
|
| 408 |
- logWrite(method, path, body, form, result.ok ? null : result); |
|
| 409 |
- |
|
| 410 | 393 |
if (!result.ok) {
|
| 394 |
+ logWriteFailure(method, path, body, form, result); |
|
| 411 | 395 |
throw new BackendRequestError(result); |
| 412 | 396 |
} |
| 413 | 397 |
|
--- lib/http/backend-fetch.ts
+++ lib/http/backend-fetch.ts
... | ... | @@ -137,6 +137,49 @@ |
| 137 | 137 |
}; |
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 |
+/** |
|
| 141 |
+ * 테스트 환경에서는 백엔드로 나가는 **모든** 요청을 서버 콘솔에 남긴다 — 브라우저 네트워크 |
|
| 142 |
+ * 탭에는 이 호출이 뜨지 않아(BFF) 여기가 유일하게 보이는 자리다. 운영에서는 찍지 않는다. |
|
| 143 |
+ * JSON 본문은 Swagger Request body에 그대로 붙여 넣을 수 있는 모양으로 찍는다. |
|
| 144 |
+ */ |
|
| 145 |
+function logRequest( |
|
| 146 |
+ method: string, |
|
| 147 |
+ url: string, |
|
| 148 |
+ payload?: { body?: unknown; form?: Record<string, string | number | undefined>; multipart?: FormData; note?: string }
|
|
| 149 |
+): void {
|
|
| 150 |
+ if (process.env.NODE_ENV === 'production') {
|
|
| 151 |
+ return; |
|
| 152 |
+ } |
|
| 153 |
+ |
|
| 154 |
+ const lines = [`[backend-fetch] ${method} ${url}`];
|
|
| 155 |
+ |
|
| 156 |
+ if (payload?.body !== undefined) {
|
|
| 157 |
+ lines.push(`body(JSON):\n${JSON.stringify(payload.body, null, 2)}`);
|
|
| 158 |
+ } |
|
| 159 |
+ if (payload?.form) {
|
|
| 160 |
+ const params = new URLSearchParams(); |
|
| 161 |
+ for (const [key, value] of Object.entries(payload.form)) {
|
|
| 162 |
+ if (value !== undefined) {
|
|
| 163 |
+ params.set(key, String(value)); |
|
| 164 |
+ } |
|
| 165 |
+ } |
|
| 166 |
+ lines.push(`form: ${params.toString()}`);
|
|
| 167 |
+ } |
|
| 168 |
+ if (payload?.multipart) {
|
|
| 169 |
+ const parts = [...payload.multipart.entries()].map(([key, value]) => |
|
| 170 |
+ value instanceof File |
|
| 171 |
+ ? `${key}=${value.name}(${Math.ceil(value.size / 1024)}KB)`
|
|
| 172 |
+ : `${key}=${String(value)}`
|
|
| 173 |
+ ); |
|
| 174 |
+ lines.push(`multipart: ${parts.join(', ')}`);
|
|
| 175 |
+ } |
|
| 176 |
+ if (payload?.note) {
|
|
| 177 |
+ lines.push(payload.note); |
|
| 178 |
+ } |
|
| 179 |
+ |
|
| 180 |
+ console.info(lines.join('\n'));
|
|
| 181 |
+} |
|
| 182 |
+ |
|
| 140 | 183 |
function resolveUrl( |
| 141 | 184 |
path: string, |
| 142 | 185 |
query: Record<string, string | number> | undefined |
... | ... | @@ -185,9 +228,12 @@ |
| 185 | 228 |
path: string, |
| 186 | 229 |
init: BackendStreamRequestInit |
| 187 | 230 |
): Promise<BackendResult<Response>> {
|
| 231 |
+ const url = resolveUrl(path, init.query); |
|
| 232 |
+ logRequest('GET', url, { note: '(파일 응답 스트림)' });
|
|
| 233 |
+ |
|
| 188 | 234 |
let response: Response; |
| 189 | 235 |
try {
|
| 190 |
- response = await fetch(resolveUrl(path, init.query), {
|
|
| 236 |
+ response = await fetch(url, {
|
|
| 191 | 237 |
method: 'GET', |
| 192 | 238 |
headers: {
|
| 193 | 239 |
...(init.accessToken |
... | ... | @@ -262,10 +308,17 @@ |
| 262 | 308 |
init: BackendRequestInit |
| 263 | 309 |
): Promise<BackendResult<T>> {
|
| 264 | 310 |
const { body, contentType } = buildRequestBody(init);
|
| 311 |
+ const url = resolveUrl(path, init.query); |
|
| 312 |
+ |
|
| 313 |
+ logRequest(init.method, url, {
|
|
| 314 |
+ body: init.body, |
|
| 315 |
+ form: init.form, |
|
| 316 |
+ multipart: init.multipart, |
|
| 317 |
+ }); |
|
| 265 | 318 |
|
| 266 | 319 |
let response: Response; |
| 267 | 320 |
try {
|
| 268 |
- response = await fetch(resolveUrl(path, init.query), {
|
|
| 321 |
+ response = await fetch(url, {
|
|
| 269 | 322 |
method: init.method, |
| 270 | 323 |
headers: {
|
| 271 | 324 |
...(contentType ? { 'Content-Type': contentType } : {}),
|
... | ... | @@ -368,9 +421,12 @@ |
| 368 | 421 |
timeoutMs?: number; |
| 369 | 422 |
} |
| 370 | 423 |
): Promise<BackendResult<T>> {
|
| 424 |
+ const url = resolveUrl(path, undefined); |
|
| 425 |
+ logRequest('POST', url, { note: '(multipart 스트림 본문 — 내용 생략)' });
|
|
| 426 |
+ |
|
| 371 | 427 |
let response: Response; |
| 372 | 428 |
try {
|
| 373 |
- response = await fetch(resolveUrl(path, undefined), {
|
|
| 429 |
+ response = await fetch(url, {
|
|
| 374 | 430 |
method: 'POST', |
| 375 | 431 |
headers: {
|
| 376 | 432 |
'Content-Type': init.contentType, |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?