p6spy

p6spy can convert the placeholder "? , :name”, etc. are converted to standard sql for output.

 

download link:

http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22p6spy%22%20AND%20a%3A%22p6spy%22

 

Documentation:

http://p6spy.github.io/p6spy/2.0/configandusage.html#confusage

 

 

How to use (1.X and 2.X have slightly different configuration methods, here is an example of configuring mysql in 2.X version):

1. Copy p6spy-2.X.jar to the lib of the project;

2. Copy spy.properties in the source code to src, that is, the compiled root path;

3. Modify driverlist=com.mysql.jdbc.Driver in spy.properties, other properties can be defaulted or modified as needed, such as enabling appender=com.p6spy.engine.spy.appender.StdoutLogger, so that you can control View the sql output on the platform, and focus on the documentation for the relevant attribute descriptions;  

4. Modify the data source configuration information in the project. For example, when using the tomcatJNDI configuration method, driverClassName="com.p6spy.engine.spy.P6SpyDriver" in the data source configuration  

and url="jdbc:p6spy:mysql://localhost:3306/dbname", other attribute configuration remains unchanged; 

5. Start tomcat, when there is hibernateHql output, it will print the converted standard sql.

 

Give a configuration information in my development environment:

driverlist=com.mysql.jdbc.Driver

dateformat=yyyy-MM-dd hh:mm:ss,SSS

appender=com.p6spy.engine.spy.appender.StdoutLogger

logMessageFormat=com.p6spy.engine.spy.appender.MultiLineFormat

databaseDialectDateFormat=yyyy-MM-dd hh:mm:ss,SSS

 

 

If you want to use log4j to output logs, you can configure it as follows:

1. Enable appender=com.p6spy.engine.spy.appender.Slf4JLogger in spy.properties;

2. The configuration in log4j.properties is as follows:

 

log4j.rootLogger=info,stdout

log.filepath=/usr/local/logs/log4j

logfile.filename=log4j_DailyRolling.log

log4j.logger.p6spy=INFO,logfile
log4j.additivity.p6spy=true

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c{1}:%L %5p - %m%n


log4j.appender.logfile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.logfile.DatePattern='.'yyyy-MM-dd
log4j.appender.logfile.File=${log.filepath}/${logfile.filename}
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d %p [%X{userName}][%X{userLocale}][%c] - <%m>%n
 

 

3. Required jar packages: p6spy-2.3.1.jar, log4j-1.2.16.jar, slf4j-api-1.6.1.jar, slf4j-log4j12-1.6.1.jar, you can also download p6spy-2.3 directly .1-log4j-nodep.jar, this one package contains the first four packages.  

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326655880&siteId=291194637