简体   繁体   中英

How to enable logging in mysql driver

How to enable logging in mysql j connector driver?

I used the following command while creating the connection

"jdbc:mysql://localhost/test?logger=com.mysql.jdbc.log.StandardLogger&profileSQL=true";

My log4j property file is like this

# Root logger option
log4j.rootLogger=TRACE,  rfile
log4j.logger.com.mysql=trace, rfile
log4j.appender.rfile = org.apache.log4j.RollingFileAppender
log4j.appender.rfile.File =PrepStmt.log
log4j.appender.rfile.MaxFileSize = 100KB
log4j.appender.rfile.Append = true
log4j.appender.rfile.layout = org.apache.log4j.PatternLayout
log4j.appender.rfile.layout.ConversionPattern= %d [%t] %-5p %c %x - %m%n

No log is getting captured in my log file.

Mysql does not know about your log4j properties.

From the docs , scroll to section Debugging/Profiling :

logger

The name of a class that implements "com.mysql.jdbc.log.Log" that will be used to log messages to. (default is "com.mysql.jdbc.log.StandardLogger", which logs to STDERR)

Default: com.mysql.jdbc.log.StandardLogger

So your mysql logs simply go to STDERR. If you want to log to a log4j defined destination you can implement com.mysql.jdbc.log.Log , forward to a log4j logger, and specify that implementation class in the connect URL.

您可以将log4jdbc配置为拦截JDBC连接并记录sql。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM