I am using log4j 2 to log messages into the mySQL DB using JDBC appender. I want to make that process asynchronous because it should support large no of users to log the data into DB at the same time. I have to prevent lock contention. I have log4j.properties as follows:
log4j.rootLogger = DEBUG, DB
# Define the DB appender
log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender
# Set JDBC URL
log4j.appender.DB.URL=jdbc:mysql://xxx.xxx.xxx.xxx:3306/test
# Set Database Driver
log4j.appender.DB.driver=com.mysql.jdbc.Driver
# Set database user name and password
log4j.appender.DB.user=root
log4j.appender.DB.password=root
# Set the SQL statement to be executed.
log4j.appender.DB.sql=INSERT INTO logs VALUES('%X{username}','%d{yyyy-MM-dd HH:mm:ss}','%C','%p','%m')
# Define the layout for file appender
log4j.appender.DB.layout=org.apache.log4j.PatternLayout
- What are the changes required in the above log4j.properties to behave asynchronously or create the corresponding log4j.xml?
- How can I configure the above properties to have a buffer size to do a batch insert into the database?