title: Get the logs of each grails cron jobs to a seperate file
body: <p>Im using grails 2.2.4 version with log4j.
  I have 15 cron jobs running at different times and some at the same time. 
  I need to get the logs of each job to a separate log file.<br>
  When a job is getting executed I need to get the log of the entire flow. </p>
  
  <p><strong>Example</strong></p>
  
  <pre><code>class SampleTestOneJob{
  
   def utilService
  
   def execute() {
   log.info "Beginning SampleTestOneJob."
   List&lt;Admin&gt; adminList = utilService.findAllAdmins()//Calling the     
  
   findAllAdmins of utilService.
   log.info "Finished SampleTestOneJob."
  
   }
  }
  
  class UtilService{
  
    def findAllAdmins() {
    log.info "Beginning findAllAdmins."
    //Implementation to get all the admins
    log.info "Finished findAllAdmins."
    }
  }
  
  class SampleTestTwoJob{
  
    def utilService
  
    def execute() {
    log.info "Beginning SampleTestTwoJob."
    //Refreshing logic 
    //Calling the findAllAdmins of utilService.
    List&lt;Admin&gt; adminList = utilService.findAllAdmins()
    log.info "Finished SampleTestTwoJob."
  
   }
  }
  </code></pre>
  
  <p>How can I get logs of SampleTestOneJob and UtilService only when SampleTestOneJob is executed.  </p>
  
  <p>How can I get logs of SampleTestTwoJob and UtilService only when SampleTestTwoJob is executed.  </p>
  
  <p>Right now using RollingFileAppender i  have done that. But the problem is when SampleTestOneJob and SampleTestTwoJob are executed. 
  Since both are calling the findAllAdmins in UtilService. The logs when calling from SampleTestOneJob to findAllAdmins will be available in SampleTestTwoJob and the logs when calling from SampleTestTwoJob to findAllAdmins will be available in SampleTestOneJob. </p>
  
  <p>Is there a way to identify for the flow and add the flow logs to the file.</p>
  
  <p><strong>Config.groovy</strong></p>
  
  <pre><code>log4j = {
  
  def logDir = 'target' + '/logs'
  def logPattern = '%d [%t] %-5p %c{2} %x - %m%n'
  
  def jobRollingFile1   = new RollingFileAppender(name: 'SampleOneLogs', layout: pattern(conversionPattern: logPattern))
  def jobRollingPolicy1 = new TimeBasedRollingPolicy(fileNamePattern: "$logDir/Logs/Sample1.%d{yyyy-MM-dd}.gz", activeFileName: "$logDir/Logs/Sample1.log")
  jobRollingPolicy1.activateOptions()
  jobRollingFile1.setRollingPolicy jobRollingPolicy1
  
  def jobRollingFile2   = new RollingFileAppender(name: 'SampleTwoLogs', layout: pattern(conversionPattern: logPattern))
  def jobRollingPolicy2 = new TimeBasedRollingPolicy(fileNamePattern: "$logDir/Logs/Sample2.%d{yyyy-MM-dd}.gz", activeFileName: "$logDir/Logs/Sample2.log")
  jobRollingPolicy2.activateOptions()
  jobRollingFile2.setRollingPolicy jobRollingPolicy2
  
  appenders {
      appender jobRollingFile1
      appender jobRollingFile2
  }
  
  info additivity: false, SampleOneLogs   : ["grails.app.jobs.SampleTestOneJob", "grails.app.services.UtilService"]
  info additivity: false, SampleTwoLogs   : ["grails.app.jobs.SampleTestTwoJob", "grails.app.services.UtilService"]
  
  }
  </code></pre>