Log4j: configure JDBC appender to use Datasource

两盒软妹~` 提交于 2019-12-05 16:44:54

If you want to use a datasource, you need to add the jar file of Apache Extras for Apache log4j1 and use the class org.apache.log4j.DBAppender2. e.g.:

# Define the root logger with file appender
log4j.rootLogger = DEBUG, sql

# Define the database appender
log4j.appender.sql=org.apache.log4j.DBAppender
log4j.appender.sql.connectionSource=org.apache.log4j.receivers.db.JNDIConnectionSource
log4j.appender.sql.connectionSource.jndiLocation=java:/comp/env/jdbc/MySQLDS

Notes

  1. You can download the file apache-log4j-extras-1.2.17.jar here.
  2. This appender uses a database schema (not customizable) and you can find it here. If you want to use other tables, you'll need to rewrite the appender.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!