title: Log Caller Class/Job Context When Spring Quartz Task Execute
body: <p>I am writing a java/spring library to include in other projects that are using quartz.
  I need it to log some information about the task/calling class everytime a job is executed.</p>
  <p>For example, if a quartz job looks like this:</p>
  <pre><code>@Bean
  public JobDetail jobADetail() {
      return JobBuilder.newJob(QuartzTaskA.class)
              .withIdentity(&quot;sampleJobA&quot;)
              .storeDurably().build();
  }
  
  @Bean
  public Trigger jobATrigger(JobDetail jobADetail) {
      return TriggerBuilder.newTrigger()
              .forJob(jobADetail)
              .withIdentity(&quot;sampleTriggerA&quot;)
              .withSchedule(CronScheduleBuilder.cronSchedule(&quot;0/10 * * ? * * *&quot;))
              .build();
  }
  
  public class QuartzTaskA implements Job {
      @Override
      public void execute(JobExecutionContext jobExecutionContext) {
          log.info(&quot;QuartzA - the time is now {}&quot;, dateFormat.format(new Date()));
      }
  }
  </code></pre>
  <p>I want it to log something like:</p>
  <pre><code>Job [QuartzTaskA] with details [sampleJobA] and trigger [sampleTriggerA] is starting
  QuartzA - the time is now 12:07:39
  </code></pre>
  <p>I customize the SchedulerFactoryBean with a custom TaskExecutor that does a log before the task.run().
  This works and I am able print the additional first line, but I can't figure out how to get the details/context to pass into the log.</p>
  <pre><code>@Configuration
  public class SchedulerFactoryCustomizer implements SchedulerFactoryBeanCustomizer {
      private static final Logger log = LogManager.getLogger(SchedulerFactoryCustomizer.class);
  
      @Override
      public void customize(SchedulerFactoryBean schedulerFactoryBean) {
          Executor executor = SchedulerFactoryBean.getConfigTimeTaskExecutor();
          schedulerFactoryBean.setTaskExecutor(new CustomExecutor(executor);
      }
  
      private static class CustomExecutor implements Executor {
          final Executor executor;
  
          private CustomExecutor(Executor executor) {
              this.executor = executor;
          }
  
          @Override
          public void execute(Runnable task) {
              // This line here. How can I get the details/context to pass in?
              //log.info(&quot;Job {} with details {} and trigger {} is starting&quot;);
              task.run();
          }
      }
  }
  </code></pre>
  <p>how can I get the details/context to pass into the log?</p>