Skip to content

[Fix] batch에서 winston 도입 이후 로그가 출력되지 않는 문제 수정 - #107

Merged
JangDongHo merged 1 commit into
devfrom
fix/batch-winston-buffer-flush
Sep 30, 2026
Merged

JangDongHo merged 1 commit into
devfrom
fix/batch-winston-buffer-flush

Conversation

@JangDongHo

@JangDongHo JangDongHo commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

📌 개요

  • batch에 winston을 도입한 이후 운영 컨테이너에서 로그가 전혀 출력되지 않는 문제 수정

✨ 작업 내용

  • services/api/batch/src/main.ts: NestFactory.create → NestFactory.createApplicationContext로 변경 (bufferLogs: true는 유지)

🔥 변경 이유

  • bufferLogs: true는 앱 초기화 중 로그를 버퍼에 쌓아 두었다가, useLogger로 지정한 로거(winston)로 flush하는 옵션
  • HTTP 앱(NestFactory.create)은 app.listen() 콜백에서만 버퍼를 flush함 (nest-application.js). app 서비스는 listen()을 호출해서 정상 출력됨
  • batch는 app.init()만 호출하고 listen()이 없어 버퍼가 한 번도 flush되지 않았고, Nest 시작 로그와 BatchService의 warn/error가 모두 버퍼에 갇혔음. 수집 잡은 스케줄러로 계속 실행되어 로그만 안 보이는 상태였음
  • batch는 HTTP 서버가 필요 없으므로 listen()을 흉내 내는 대신, useLogger 시점에 자동 flush하는 createApplicationContext를 사용

🧪 테스트

  • 정상 동작 확인: NODE_ENV=production, DB 없이 winston 배선만 검증한 프로브로 비교
    • 수정 전(create + bufferLogs, flush 없음): 0줄
    • bufferLogs 끔: 10줄 / app.flushLogs() 추가: 10줄 / createApplicationContext: 9줄
  • batch nest build, eslint, jest 전체 통과 (17 suites, 83 tests)
  • 실제 main.ts로 winston 출력 확인은 하지 못함. 로컬에 DB가 없어 초기화 단계에서 실패하며, 이때는 Nest 기본 로거 형식으로 출력됨. 배포 후 docker compose logs batch에서 [connect-gnu-batch] 형식의 시작 로그가 나오는지 확인 필요
  • 배포 후 프로세스가 계속 유지되는지 확인 (listen() 없이 스케줄러가 이벤트 루프를 유지하는 구조는 기존과 동일, 배포 워크플로의 20초 상태 확인으로 검증)

🔗 관련 이슈

  • 없음

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 개선 사항
    • 배치 모듈이 HTTP 애플리케이션 대신 NestJS 애플리케이션 컨텍스트에서 실행되도록 변경했습니다.

- NestFactory.create는 app.listen() 시점에만 버퍼 로그를 flush하는데,
  batch는 listen()을 호출하지 않아 winston 도입 이후 로그가 전혀 출력되지 않았음
- HTTP 서버가 필요 없으므로 createApplicationContext로 변경하여
  useLogger 시점에 버퍼 로그가 자동 flush되도록 함

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: GNU-connect/Server-Node/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8242aacc-0c46-4237-ab4c-1f78390eb56b

📥 Commits

Reviewing files that changed from the base of the PR and between 85aeb7c and 9c34d42.

📒 Files selected for processing (1)
  • services/api/batch/src/main.ts
 __________________________________________________________
< Solving problems you didn't know you were about to have. >
 ----------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JangDongHo JangDongHo self-assigned this Sep 30, 2026
@JangDongHo
JangDongHo merged commit 383f012 into dev Sep 30, 2026
1 of 2 checks passed
@JangDongHo
JangDongHo deleted the fix/batch-winston-buffer-flush branch September 30, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant