我必须配置JDBC appender才能使用数据源。它可能吗?
如果是这样,怎么样? 我现在的文件是这样的:# Define the root logger with file appender
log4j.rootLogger = DEBUG, sql
# Define the file appender
log4j.appender.sql=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.sql.URL=jdbc:mysql://localhost/test
# Set Database Driver
log4j.appender.sql.driver=com.mysql.jdbc.Driver
# Set database user name and password
log4j.appender.sql.user=root
log4j.appender.sql.password=password
# Set the SQL statement to be executed.
log4j.appender.sql.sql=INSERT INTO LOGS VALUES ('%x', now() ,'%C','%p','%m')
# Define the xml layout for file appender
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
答案 0 :(得分:1)
如果要使用数据源,则需要添加Apache Extras for Apache log4j 1 的jar文件并使用类org.apache.log4j.DBAppender
2 。 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
备注的