Reputation: 77
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.
Upvotes: 0
Views: 6913
Reputation: 32980
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.
Upvotes: 1
Reputation: 27986
You could configure log4jdbc to intercept the JDBC connection and log the sql.
Upvotes: 0