jdbc配置profilesql参数 追踪日志记录执行的sql

最简单的就是直接在jdbc db url加profileSQL=true,会在stderr输出sql执行情况,有毫秒日志。
Add 'logger' and 'profileSQL' to the jdbc url:

&logger=com.mysql.jdbc.log.Slf4JLogger&profileSQL=true

Then you will get the SQL statement below:

The default logger is:

com.mysql.jdbc.log.StandardLogger

Mysql jdbc property list: https://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

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. 

© 2017, 新之助meow. 原创文章转载请注明: 转载自http://www.xinmeow.com

0.00 avg. rating (0% score) - 0 votes
点赞