임동욱 임동욱 08-21
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
+++ lib/data/repositories/content-repository.ts
@@ -347,29 +347,18 @@
 }
 
 /**
- * 보낸 것을 서버 콘솔에 그대로 남긴다.
- *
- * 브라우저 네트워크 탭에는 이 요청이 **뜨지 않는다** — 화면은 Server Action을 부르고 백엔드
- * 호출은 서버에서 일어난다(BFF). 그래서 개발 중에는 성공·실패를 가리지 않고 찍고, 운영에서는
- * 실패만 남긴다. JSON은 Swagger의 Request body에 그대로 붙여 넣을 수 있는 모양이다.
+ * 실패한 쓰기의 사유와 보낸 본문을 남긴다. 요청 자체는 테스트 환경에서 backend-fetch가
+ * 전부 찍으므로(중앙 로거) 여기는 실패만 맡는다 — 운영에서도 원인 추적에 이게 유일한 단서다.
  */
-function logWrite(
+function logWriteFailure(
   method: string,
   path: string,
   body: unknown,
   form: Record<string, string | number | undefined> | undefined,
-  failure: { code: number; message: string } | null
+  failure: { code: number; message: string }
 ): void {
-  if (failure === null && process.env.NODE_ENV === 'production') {
-    return;
-  }
-
-  const head = failure
-    ? `[contents] ${method} ${path} 실패 (code ${failure.code}: ${failure.message})`
-    : `[contents] ${method} ${path}`;
-
   const lines = [
-    head,
+    `[contents] ${method} ${path} 실패 (code ${failure.code}: ${failure.message})`,
     body === undefined ? null : `body(JSON):\n${JSON.stringify(body, null, 2)}`,
     form === undefined
       ? null
@@ -380,11 +369,7 @@
         ).toString()}`,
   ].filter(Boolean);
 
-  if (failure) {
-    console.error(lines.join('\n'));
-  } else {
-    console.info(lines.join('\n'));
-  }
+  console.error(lines.join('\n'));
 }
 
 async function sendWrite(
@@ -405,9 +390,8 @@
     canHaveEmptyBody: true,
   });
 
-  logWrite(method, path, body, form, result.ok ? null : result);
-
   if (!result.ok) {
+    logWriteFailure(method, path, body, form, result);
     throw new BackendRequestError(result);
   }
 
lib/http/backend-fetch.ts
--- lib/http/backend-fetch.ts
+++ lib/http/backend-fetch.ts
@@ -137,6 +137,49 @@
   };
 }
 
+/**
+ * 테스트 환경에서는 백엔드로 나가는 **모든** 요청을 서버 콘솔에 남긴다 — 브라우저 네트워크
+ * 탭에는 이 호출이 뜨지 않아(BFF) 여기가 유일하게 보이는 자리다. 운영에서는 찍지 않는다.
+ * JSON 본문은 Swagger Request body에 그대로 붙여 넣을 수 있는 모양으로 찍는다.
+ */
+function logRequest(
+  method: string,
+  url: string,
+  payload?: { body?: unknown; form?: Record<string, string | number | undefined>; multipart?: FormData; note?: string }
+): void {
+  if (process.env.NODE_ENV === 'production') {
+    return;
+  }
+
+  const lines = [`[backend-fetch] ${method} ${url}`];
+
+  if (payload?.body !== undefined) {
+    lines.push(`body(JSON):\n${JSON.stringify(payload.body, null, 2)}`);
+  }
+  if (payload?.form) {
+    const params = new URLSearchParams();
+    for (const [key, value] of Object.entries(payload.form)) {
+      if (value !== undefined) {
+        params.set(key, String(value));
+      }
+    }
+    lines.push(`form: ${params.toString()}`);
+  }
+  if (payload?.multipart) {
+    const parts = [...payload.multipart.entries()].map(([key, value]) =>
+      value instanceof File
+        ? `${key}=${value.name}(${Math.ceil(value.size / 1024)}KB)`
+        : `${key}=${String(value)}`
+    );
+    lines.push(`multipart: ${parts.join(', ')}`);
+  }
+  if (payload?.note) {
+    lines.push(payload.note);
+  }
+
+  console.info(lines.join('\n'));
+}
+
 function resolveUrl(
   path: string,
   query: Record<string, string | number> | undefined
@@ -185,9 +228,12 @@
   path: string,
   init: BackendStreamRequestInit
 ): Promise<BackendResult<Response>> {
+  const url = resolveUrl(path, init.query);
+  logRequest('GET', url, { note: '(파일 응답 스트림)' });
+
   let response: Response;
   try {
-    response = await fetch(resolveUrl(path, init.query), {
+    response = await fetch(url, {
       method: 'GET',
       headers: {
         ...(init.accessToken
@@ -262,10 +308,17 @@
   init: BackendRequestInit
 ): Promise<BackendResult<T>> {
   const { body, contentType } = buildRequestBody(init);
+  const url = resolveUrl(path, init.query);
+
+  logRequest(init.method, url, {
+    body: init.body,
+    form: init.form,
+    multipart: init.multipart,
+  });
 
   let response: Response;
   try {
-    response = await fetch(resolveUrl(path, init.query), {
+    response = await fetch(url, {
       method: init.method,
       headers: {
         ...(contentType ? { 'Content-Type': contentType } : {}),
@@ -368,9 +421,12 @@
     timeoutMs?: number;
   }
 ): Promise<BackendResult<T>> {
+  const url = resolveUrl(path, undefined);
+  logRequest('POST', url, { note: '(multipart 스트림 본문 — 내용 생략)' });
+
   let response: Response;
   try {
-    response = await fetch(resolveUrl(path, undefined), {
+    response = await fetch(url, {
       method: 'POST',
       headers: {
         'Content-Type': init.contentType,
Add a comment
List