The goal of this short example is to show how to configure a log4j2 database appender, and making it using the database configuration
from a Spring properties file.
- Spring Boot 1.4.0.RELEASE
- Oracle 12g
We need to define the dependency to the log4j2 starter.
The starter is going to import the following libraries:
Create the log table
Of course, we have to create a table for the logs. This is a simple example, feel free to adapt it to your needs:
I found it easier to register the appender programmatically during the startup of the application context. Here how it works, I created
a Spring configuration file dedicated to it:
The final step is the connection source. Here are the sources:
A datasource is initialized in the constructor of the class, and then the idea is to override the method getConnection.