Sep 28th, 2012, 01:56 PM
Multiple Loggers for Spring batch application with 3 different jobs
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.
- Job 1 - Reads file from folder , validates file and starts a job.
- Job 2 - Job started Started by Cron expression, reads from table and writes to a file.
- 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?
Oct 1st, 2012, 01:58 PM
I think you could accomplish this by configuring your logger via the Java API at runtime.
Oct 2nd, 2012, 02:10 AM
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
Oct 2nd, 2012, 03:46 PM
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!
Oct 3rd, 2012, 10:16 PM
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.
Tags for this Thread