Announcement Announcement Module
Collapse
No announcement yet.
Multiple Loggers for Spring batch application with 3 different jobs Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple Loggers for Spring batch application with 3 different jobs

    Hi There,

    We have a single Spring batch application which consists of 3 different jobs: The following jobs have their own processors, writers etc. Each job does different things i.e. they are unique. The jobs are run at different times.
    1. Job 1 - Reads file from folder , validates file and starts a job.
    2. Job 2 - Job started Started by Cron expression, reads from table and writes to a file.
    3. Job 3 - Reads file from folder , validates file and starts a job.

    WE want separate log files for the above 3 jobs. The log file should contain all logging done by Spring batch framework for each of the above jobs in a separate file.

    I can configure 3 different appenders in log4j config file and manage logging to the custom components we create (like processors/writers etc) but would also need the Spring batch logging like job/step related logging to be also on the respective log file.

    Is it possible? If so how do we implement it?

  • #2
    I think you could accomplish this by configuring your logger via the Java API at runtime.

    Jeff

    Comment


    • #3
      Ok, Got me thinking in the right direction! Thanks Jeff.

      I am thinking of getting the respective File Appenders at runtime as configured in log4j xml, activate it @beforeJob and then de-activate it at @afterJob (in in the Job Execution listener).

      Will update how it went later

      Comment


      • #4
        This is related to this Jira issue:https://jira.springsource.org/browse/BATCH-1704. If you are successful with it, please feel free to offer a pull request!

        Comment


        • #5
          Thanks MMinella.

          I was able to use the solution from Dave Syer as per the URL below by using Log4j DispatcherAppender. It fits perfectly in our Spring batch application. This allowed us to have separate log files for each job. I can see all related logging from reader/processor/writer in the respective log file.

          https://github.com/dsyer/log4j-utils [url was picked up from the jira url above]

          Have deployed this change into our test env and see how it goes for a week and any issues encountered will update here.

          Comment

          Working...
          X