feat: 배치 Job·Step 식별자를 MDC 에 싣는 리스너와 실행 요약 로그 리스너 추가 - #433
Open
comghost wants to merge 1 commit into
Open
Conversation
배치 로그는 여러 Job 이 한 파일에 섞여 Job 별로 나누거나 실행 단위로 추적하기 어렵고, 실행이 끝났을 때 읽기·쓰기·건너뜀 건수를 한 줄로 남기는 표준 지점이 없어 관제 시스템이 상세 로그를 파싱해야 한다. - EgovBatchMdcListener(JobExecutionListener + StepExecutionListener): Job 이름· JobExecution ID·Step 이름을 SLF4J MDC(batchJobName·batchJobExecutionId· batchStepName)에 넣고 종료 시 지운다. Log4j2 RoutingAppender 와 조합하면 Job 별 로그 파일 분리를 재기동 없이 구성할 수 있다 - EgovBatchSummaryListener(JobExecutionListener): Job 종료 시 전용 로거 EGOV_BATCH_SUMMARY 에 job= executionId= status= exitCode= durationMs= steps= read= written= skipped= filtered= 형식의 한 줄을 남긴다. 값은 Step 실행 결과를 합산한다 - 두 리스너 모두 빈으로 등록해 Job 에 붙이며 기존 클래스 수정·의존 추가 없음. 멀티스레드 Step 에서 MDC 가 워커 스레드로 전파되지 않는 점은 javadoc 에 명시 EgovBatchListenersTest 3건 추가 — MDC 키 주입과 Step·Job 종료 시 제거, 실행 요약의 Step 건수 합산과 형식, 시작·종료 시각이 없을 때 durationMs=-1 과 JobInstance 없을 때 job=?.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
수정 사유 Reason for modification
수정된 소스 내용 Modified source
배경
배치 로그는 여러 Job 이 한 파일에 섞여 Job 별로 나누거나 실행 단위(JobExecution)로 추적하기 어렵습니다. 실행이 끝났을 때
읽기·쓰기·건너뜀 건수를 한 줄로 남기는 표준 지점도 없어 관제·수집 시스템이 상세 로그를 파싱해야 합니다.
추가한 것
1.
operation/EgovBatchMdcListener—JobExecutionListener+StepExecutionListenerJob 이름·JobExecution ID·Step 이름을 SLF4J MDC 에 넣고 종료 시 지웁니다.
batchJobNamebatchJobExecutionIdbatchStepNameLog4j2
RoutingAppender와 조합하면 Job 별 로그 파일 분리를 재기동 없이 구성할 수 있습니다.2.
operation/EgovBatchSummaryListener—JobExecutionListenerJob 종료 시 전용 로거
EGOV_BATCH_SUMMARY(INFO)에 실행 결과를 key=value 한 줄로 남깁니다. 값은 Step 실행 결과를 합산합니다.설계 메모
등록하지 않은 애플리케이션에는 영향이 없습니다.
taskExecutor)에서는 MDC 가 워커 스레드로 자동 전파되지 않는 점을 javadoc 에 명시했습니다.spring.batch.job/spring.batch.step)을 쓰고, 이 리스너는실행 단위 요약 한 줄만 담당합니다.
JUnit 테스트 JUnit tests
EgovBatchListenersTest3건 신규,bat.core모듈은 Linux 전건 통과, Windows 는 기존 테스트 1건이main에서도 실패(아래 표).Tests run: 104, Failures: 1, Errors: 0, Skipped: 0— 실패 1건은 이 PR 과 무관한 기존 테스트DefaultItemGuidanceKeyTest.writerDelimitedFileGuidance로, 변경 없는main(cc2b332) 에서도 Windows 에서만 같은 실패가 납니다(Linux 는 통과). 신규 3건은 통과Tests run: 104, Failures: 0, Errors: 0, Skipped: 0durationMs=-1, JobInstance 가 없으면job=?수동 확인: 현재
main(cc2b332) 위에서bat.core모듈 빌드·테스트가 Linux 에서 전건 통과함을 확인했습니다. Windows 에서 실패하는DefaultItemGuidanceKeyTest.writerDelimitedFileGuidance1건은 변경 전main에서도 같은 방식으로 실패해 이 PR 과 무관합니다.테스트 브라우저 Test Browser
해당 없음 — 배치 라이브러리 클래스 추가입니다.
테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video
해당 없음 — 위 JUnit 테스트 결과로 갈음합니다.
base:
eGovFramework:main@cc2b332(2026-09-10 fetch 기준, #366~#379 머지 후) · 단일 커밋