0

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.

1
  • Direct Log4J logging was dropped from version 3.1.1 of Connector/J Commented Sep 18, 2015 at 13:41

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi I tried following you comment and implemented com.mysql.jdbc.log.Log then I specified my class (fully qualified path) jdbc.JdbcLogger in connection url. However I get class not found exception from com.mysql.jdbc.log.LogFactory line 66 since it can not load this class. I can load the the class separately though using Class.forName("jdbc.JdbcLogger). Using mysql-connector-java-5.1.38. Any idea what may be wrong?
0

You could configure log4jdbc to intercept the JDBC connection and log the sql.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.