street
street

Reputation: 51

Logging in Spring batch

I am new to spring batch. I want to know how we can put logging statement while implementing spring batch readers and writers. For example if I define readers and writers in spring context XML then later on I can't debug where my code failed. How can I achieve logging in Spring batch. Do I need to extend the available reader classes in java for example flatFileReader and put logging statement in java class.

Or can I achieve this while maintaining my code in context file?

And in case I want to throw my user defined exceptions then how can I do this.

Upvotes: 3

Views: 27152

Answers (3)

korayguney
korayguney

Reputation: 179

There is an advanced listener architecture at Spring Batch API. You can use listener classes/interfaces to manage your logging such as ItemListenerSupport, ItemReadListener, ItemProcessListener or ItemWriteListener. Just implement/extend the class/interfaces that you need and customize the listener methods with overriding according to your needs.

For logging exceptions, please refer to this link.

Upvotes: 1

Alex Fernandez
Alex Fernandez

Reputation: 1942

Use Slf4j for logging, using sl4j you could log anything inside your batch job

 log.info("Converting (" + jobDetails + ") into (" + transformedJobDetails + ")");

Upvotes: 0

Saifuddin Merchant
Saifuddin Merchant

Reputation: 1171

Depending on what you want to debug, if you looking for debugging the out-of-the-box readers and writers, set up your log4j level to debug for the spring batch package.

###  debug your specific package or classes with the following example
#log4j.logger.org.springframework.jdbc=debug
#log4j.logger.org.springframework.batch=debug

Most of the out-of-box readers and writers should have sufficient debugging.

Upvotes: 5

Related Questions