1 package net.sf.bacchus.spring;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.springframework.batch.core.ItemProcessListener;
6 import net.sf.bacchus.Record;
7
8 /**
9 * {@link ItemProcessListener} for {@link Record} processors sends the records
10 * to a {@link Log}.
11 */
12 public class RecordProcessLogger implements ItemProcessListener<Record, Record> {
13
14 /** Log that receives the record processing messages. */
15 private Log logger = LogFactory.getLog(getClass());
16
17 /**
18 * Logs the result as an {@link Log#info(Object)}.
19 * @param item Ignored.
20 * @param result the record that is logged.
21 */
22 public void afterProcess(final Record item, final Record result) {
23 this.logger.info(result);
24 }
25
26 /**
27 * Logs the item as an {@link Log#info(Object)}.
28 * @param item the record that is logged.
29 */
30 public void beforeProcess(final Record item) {
31 this.logger.info(item);
32 }
33
34 /**
35 * Logs the exception as an {@link Log#error(Object, Throwable)}.
36 * @param item the record that caused the exception.
37 * @param e {@inheritDoc}
38 */
39 public void onProcessError(final Record item, final Exception e) {
40 this.logger.error(item, e);
41 }
42
43 /**
44 * Sets the name of the process logger.
45 * @param name the name of the process logger.
46 */
47 public void setLogName(final String name) {
48 this.logger = LogFactory.getLog(name);
49 }
50
51 }