I'm new to using Spring, SLF4J, & Logback. I'm trying to implement a custom Database Appender that will only log specific types of exceptions to a database during Spring Batch processing.
So far I've started to setup a Logback Database Appender that extends the AppenderBase class and then an initializer that extends the InitializingBean in spring so it adds the appender to the root logger once Spring has initialized (So I can use my DB information from spring.xml).
How can I set this appender/logger up so I can only log certain exceptions to my custom tables?
EDIT: After doing some more research, let me ask an additional question to verify. If I were to create a custom logger like "SpecialExceptionLogger", can I just add the DB Appender to that specific logger and then use that logger when I get the special exceptions?
Your requirement of "appender using Spring's DB info" is a bit strange. Logging is already available during Spring startup, and in case the log during the startup needs to go thru that appender, it won't work because your appender cannot be properly configured yet. I'd recommend you configure your appender separately (although it is not impossible to achieve what you look for)
For your other questions:
If I were to create a custom logger like "SpecialExceptionLogger", can I just add the DB Appender to that specific logger and then use that logger when I get the special exceptions?
Of course you can. It should be basics of using Logback. Make sure you read the documents to learn the basics first.
XML will look like (not real one, just give you idea)
<appender name="dbAppender" ...> ... </appender>
<logger name="SpecialExceptionLogger">
<appender-ref ref="dbAppender"/>
</logger>
How can I set this appender/logger up so I can only log certain exceptions to my custom tables
I believe filter in Logback can achieve what you need. You can find it in an existing answer in StackOverflow