P6spy sql跟踪使用
来源:互联网 发布:音频编辑软件for mac 编辑:程序博客网 时间:2024/05/20 12:22
P6spy sql跟踪使用
1 准备
2 使用
将p6spy.jar加入工程的lib中
将spy.properties加入到工程classpath下面
3 配置
配置原始的driverClassName为com.p6spy.engine.spy.P6SpyDriver;
配置spy.properties
配置真实驱动realdriver=com.mysql.jdbc.Driver
配置日志等级以及不需要日志的类型
excludecategories=info,debug,result,batch,resultset
《spy.properties》
module.log=com.p6spy.engine.logging.P6LogFactory
#module.outage=com.p6spy.engine.outage.P6OutageFactory
# oracle driver
#realdriver=oracle.jdbc.driver.OracleDriver
#mysql Connector/J driver
realdriver=com.mysql.jdbc.Driver
#informix driver
#realdriver=com.informix.jdbc.IfxDriver
#ibm db2 driver
#realdriver=COM.ibm.db2.jdbc.net.DB2Driver
# themysql open sourcedriver
#realdriver=org.gjt.mm.mysql.Driver
#specifies another driver to use
realdriver2=
#specifies a third driver to use
realdriver3=
deregisterdrivers=false
executionthreshold=
outagedetection=false
outagedetectioninterval=
################################################################
# COMMON PROPERTIES #
################################################################
# filter what is logged
filter=false
# comma separated list of tablesto include when filtering
include =
# comma separated list of tablesto exclude when filtering
exclude =
#sql expression toevaluate if usingregex filtering
sqlexpression =
# turn on tracing
autoflush =true
# sets the date format usingJava's SimpleDateFormat routine
dateformat=
#list of categories to explicitlyinclude
includecategories=
#list of categories to exclude:error, info, batch, debug, statement,
#commit,rollback andresult are valid values
excludecategories=info,debug,result,batch,resultset
#allows you to use aregexengine or your own matching engine to determine
#which statements to log
#
#stringmatcher=com.p6spy.engine.common.GnuRegexMatcher
#stringmatcher=com.p6spy.engine.common.JakartaRegexMatcher
stringmatcher=
# prints a stack trace for everystatement logged
stacktrace=false
# ifstacktrace=true,specifies the stack trace to print
stacktraceclass=
# determines if property fileshould be reloaded
reloadproperties=false
# determines how often should bereloaded in seconds
reloadpropertiesinterval=60
#if=true thenurl must beprefixed with p6spy:
useprefix=false
#specifies the appender to use forlogging
appender=com.p6spy.engine.logging.appender.Log4jLogger
#appender=com.p6spy.engine.logging.appender.StdoutLogger
#appender=com.p6spy.engine.logging.appender.FileLogger
# name oflogfile to use,note Windows users should make sure to use forward slashes in their pathname(e:/test/spy.log) (used for file logger only)
logfile =d:/log/eorder_spy.log
# append to the p6spy log file. if this is set to false the
# log file is truncated everytime. (file logger only)
append=true
log4j.appender.logf=org.apache.log4j.RollingFileAppender
log4j.appender.logf.File=d:/log/eorder_spy.log
log4j.appender.logf.MaxFileSize=10240KB
log4j.appender.logf.layout=org.apache.log4j.PatternLayout
log4j.appender.logf.layout.ConversionPattern=p6spy-%m%n
#Keep three backup files.
log4j.appender.logf.MaxBackupIndex=5
#The following are for log4jlogging only
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=p6spy-%m%n
log4j.appender.SQLPROFILER_CLIENT=org.apache.log4j.net.SocketAppender
log4j.appender.SQLPROFILER_CLIENT.RemoteHost=localhost
log4j.appender.SQLPROFILER_CLIENT.Port=4445
log4j.appender.SQLPROFILER_CLIENT.LocationInfo=true
#log4j.logger.p6spy=INFO,STDOUT
#log4j.logger.p6spy=DEBUG,logf,SQLPROFILER_CLIENT
log4j.logger.p6spy=DEBUG,STDOUT
4 注意说明
4.1 resultset
p6spy会将对查询结果的每条数据记录日志,这样导致调试不方便,日志文件增大速度快。
然而p6spy已经停止升级更新。对此修改源码如下
com.p6spy.engine.spy. P6ResultSet
public boolean next()
throwsSQLException
{
if(this.currRow > -1) {
StringBuffer buffer = new StringBuffer();
String comma = "";
for(Iterator itr = this.resultMap.keySet().iterator(); itr.hasNext(); ) {
String index = (String)itr.next();
buffer.append(comma);
buffer.append(index);
buffer.append(" = ");
buffer.append((String)this.resultMap.get(index));
comma = ", ";
}
P6LogQuery.log("resultset", query,buffer.toString());
this.resultMap.clear();
}
this.currRow += 1;
returnthis.passthru.next();
}
改为(让resultset能够配置)
public boolean next()
throwsSQLException
{
if(this.currRow > -1) {
StringBuffer buffer = new StringBuffer();
String comma = "";
for(Iterator itr = this.resultMap.keySet().iterator(); itr.hasNext(); ) {
String index = (String)itr.next();
buffer.append(comma);
buffer.append(index);
buffer.append(" = ");
buffer.append((String)this.resultMap.get(index));
comma = ", ";
}
P6Connection p6connection =(P6Connection)this.statement.getConnection();
P6LogQuery.logElapsed(p6connection.getId(), System.currentTimeMillis(),"resultset", this.preparedQuery, this.query);
this.resultMap.clear();
}
this.currRow += 1;
returnthis.passthru.next();
}
publicvoidlogSQL(intconnectionId, String now, longelapsed, String category, String prepared, String sql) {
String logEntry = now + "|"+ elapsed +"|"+(connectionId==-1 ? "" :String.valueOf(connectionId))+"|"+category+"|"+prepared+"|"+sql;
logText(logEntry);
}
改为如下(优化sql日志)
public void logSQL(int connectionId, Stringnow, long elapsed, String category, String prepared, String sql)
{
long n = Long.parseLong(now);
String nowDate = newSimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(n));
sql = sql.replaceAll("\\s+"," ");
String logEntry = nowDate + "|" +elapsed + "|" + (connectionId != -1 ? String.valueOf(connectionId) :"") + "|" + category + "|" + sql;
logText(logEntry);
}
重新编译打包
5 下载
相关文件下载
下载中p6spy.jar已经修改了源码
http://download.csdn.net/detail/u010648190/7643329
- P6spy sql跟踪使用
- sql跟踪工具——p6spy
- P6SPY和SQL Profiler使用
- P6SPY、SQL Profiler结合使用
- 使用P6Spy格式化SQL语句
- P6Spy源码分析,理解跟踪SQL的工作原理
- P6Spy源码分析,理解跟踪SQL的工作原理
- 为你的 项目安装Sql跟踪工具-P6Spy
- sql性能监控(p6spy使用)
- 使用p6spy监视mybatis输出sql
- 我的SQL在哪里--SQL跟踪工具P6Spy介绍(s00n原作)
- 关于P6Spy、SQL profiler和Irontrack SQL的使用文档
- 【p6spy】程序员开发利器P6spy——打印执行sql语句,mybatis、ibatis、Hibernate均可使用
- 使用 P6Spy+sqlprofiler 监听和分析JDBC SQL语句
- 使用p6spy新版监控分析sql输出log日志
- Spring4.0.2使用p6spy打印mybatis执行SQL
- 使用 P6Spy 来格式化 SQL 语句,支持 Hibernate 和 iBATIS
- DBminitor|P6Spy---- record sql
- poj 1328 Radar Installation
- poi 3.9 Range发现一个bug
- linux下libxml2库的使用说明
- ------Java基础强化------适合初学者
- Code blocks error: 'thread' is not a member of 'std'|
- P6spy sql跟踪使用
- Hadoop Mapreduce从零开始
- hdu1969
- 设置了error_reporting(E_ALL)还是不显示错误
- HDU 4255 A Famous Grid
- 交大OJ 2113题
- 扩展欧几里得算法
- java一个多线程的经典例子
- IM系统中聊天记录模块的设计与实现