package be.raildelays.batch.listener;

import org.apache.logging.log4j.ThreadContext;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;

/**
 * Add jobExecutionId to {@link org.apache.logging.log4j.ThreadContext} to be able to create
 * log direction based on that number.
 *
 * @author Almex
 */
public class LoggerContextJobListener implements JobExecutionListener {


    public static final String JOB_EXECUTION_ID = "jobExecutionId";
    public static final String JOB_INSTANCE_ID = "jobInstanceId";

    @Override
    public void beforeJob(JobExecution jobExecution) {
        ThreadContext.put(JOB_EXECUTION_ID, jobExecution.getId().toString());
        ThreadContext.put(JOB_INSTANCE_ID, jobExecution.getJobId().toString());
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        ThreadContext.remove(JOB_EXECUTION_ID);
        ThreadContext.remove(JOB_INSTANCE_ID);
    }
}

@@ -47,42 +47,17 @@
 org.
-apache.logging.log4j.ThreadContext
+slf4j.MDC
 ;%0Aim
@@ -167,16 +167,75 @@
 tener;%0A%0A
+import java.text.SimpleDateFormat;%0Aimport java.util.Date;%0A%0A
 /**%0A * A
@@ -593,16 +593,81 @@
 anceId%22;
+%0A    public static final String DATE_PARAMETER = %22dateParameter%22;
 %0A%0A    @O
@@ -733,37 +733,96 @@
 ) %7B%0A        
-ThreadContext
+Date date = jobExecution.getJobParameters().getDate(%22date%22);%0A        MDC
 .put(JOB_EXE
@@ -874,29 +874,19 @@
         
-ThreadContext
+MDC
 .put(JOB
@@ -932,24 +932,106 @@
 oString());%0A
+        MDC.put(DATE_PARAMETER, new SimpleDateFormat(%22yyyy-MM-dd%22).format(date));%0A
     %7D%0A%0A    @
@@ -1097,37 +1097,27 @@
 ) %7B%0A        
-ThreadContext
+MDC
 .remove(JOB_
@@ -1139,29 +1139,19 @@
         
-ThreadContext
+MDC
 .remove(
@@ -1164,20 +1164,56 @@
 STANCE_ID);%0A
+        MDC.remove(DATE_PARAMETER);%0A
     %7D%0A%7D%0A

Update LoggerContextJobListener.java