Announcement Announcement Module
Collapse
No announcement yet.
How to log to different files using spring batch Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to log to different files using spring batch

    I am using log4j.properties files for logging.
    Code:
    log4j.appender.chainsaw=org.apache.log4j.RollingFileAppender
    log4j.appender.chainsaw.File=import_log.xml
    log4j.appender.chainsaw.Append=false
    log4j.appender.chainsaw.Threshold=debug
    log4j.appender.chainsaw.MaxFileSize=10MB
    log4j.appender.chainsaw.MaxBackupIndex=2
    log4j.appender.chainsaw.layout=org.apache.log4j.xml.XMLLayout 
    
    log4j.rootCategory=info, format077Job
    log4j.appender.format077Job.File=format077Job.xml
    log4j.appender.format007Job=org.apache.log4j.RollingFileAppender
    log4j.appender.format077Job.layout=org.apache.log4j.PatternLayout
    log4j.appender.format077Job.layout.ConversionPattern=%d [%5p] %m%n
    
    
    log4j.rootCategory=info, format529Job
    log4j.appender.format529Job.File=format529Job.xml
    log4j.appender.format529Job=org.apache.log4j.RollingFileAppender
    log4j.appender.format529Job.layout=org.apache.log4j.PatternLayout
    log4j.appender.format529Job.layout.ConversionPattern=%d [%5p] %m%n
    However my both jobs format077job and format529job runs at the same time and log into same log file.

    I want to have seperate log file for each job instance. So even if they run in parallel they will log to different log files. How I can achieve this please help.

  • #2
    Have you tried having a job listener (or step listener, depending upon how you are executing the job) and dynamically setting the log4j log file name in beforeJob (or beforeStep)?? Just a thought. let us know if that works.

    Comment


    • #3
      I tried other way.

      Hi I tried some configuration in log4j.properties to log to different files.

      I am using 2 different RollingFileAppender which are logging to different files.
      And using them for different jobs.

      Code:
      log4j.appender.chainsaw=org.apache.log4j.RollingFileAppender
      log4j.appender.chainsaw.File=/opt/oasis/bulk/log/import077.log
      log4j.appender.chainsaw.Append=false
      log4j.appender.chainsaw.Threshold=error
      log4j.appender.chainsaw.MaxFileSize=10MB
      log4j.appender.chainsaw.MaxBackupIndex=2
      log4j.appender.chainsaw.layout=org.apache.log4j.xml.XMLLayout
      
      log4j.appender.append529=org.apache.log4j.RollingFileAppender
      log4j.appender.append529.File=/opt/oasis/bulk/log/import529.log
      log4j.appender.append529.Append=false
      log4j.appender.append529.Threshold=debug
      log4j.appender.append529.MaxFileSize=10MB
      log4j.appender.append529.MaxBackupIndex=2
      log4j.appender.append529.layout=org.apache.log4j.xml.XMLLayout
      
      log4j.rootCategory=error, format077Job
      log4j.appender.format007Job=chainsaw
      log4j.appender.format077Job.File=format077Job.xml
      log4j.appender.format077Job.layout=org.apache.log4j.PatternLayout
      log4j.appender.format077Job.layout.ConversionPattern=%d [%5p] %m%n
      
      
      log4j.rootCategory=info, format529Job
      log4j.appender.format529Job.File=format529Job.xml
      log4j.appender.format529Job=append529
      log4j.appender.format529Job.layout=org.apache.log4j.PatternLayout
      log4j.appender.format529Job.layout.ConversionPattern=%d [%5p] %m%n
      This way it is working however I don't know if this is the right way to do this.

      In this case I have to configure different appender for all the jobs.

      No of jobs = No of appender .....doesn't sound good ;-)

      Comment

      Working...
      X