2019-04-01 p6spy使用

1、添加依賴

<dependency>

? ? <groupId>p6spy</groupId>

? ? <artifactId>p6spy</artifactId>

? ? <version>3.7.0</version>

</dependency>

2、新建spy.properties

# 自定義日志打印

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

customLogMessageFormat=%(currentTime) | SQL耗時: %(executionTime) ms | 連接信息: %(category)-%(connectionId) | 執(zhí)行語句: %(sql)

module.log=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory

# 自定義日志打印

#logMessageFormat=org.pkaq.core.log.P6SpyLogger

# 使用日志系統(tǒng)記錄sql

appender=com.p6spy.engine.spy.appender.Slf4JLogger

## 配置記錄Log例外

excludecategories=info,debug,result,batc,resultset

# 設(shè)置使用p6spy driver來做代理

deregisterdrivers=true

# 日期格式

dateformat=yyyy-MM-dd HH:mm:ss

# 實際驅(qū)動

driverlist=com.mysql.jdbc.Driver

# 是否開啟慢SQL記錄

outagedetection=true

# 慢SQL記錄標準 秒

outagedetectioninterval=2


也可以自定義輸出格式

3、修改數(shù)據(jù)庫配置文件

spring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver

spring.datasource.url=jdbc:p6spy:mysql:///houserent?serverTimezone=GMT%2B8


http://www.itdecent.cn/p/199d5f78aa66? ?

(文件內(nèi)容太多了,僅附上幾處重要的)

#################################################################

# MODULES? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

# Modules provide the P6Spy functionality.? If a module, such? #

# as module_log is commented out, that functionality will not? #

# be available.? If it is not commented out (if it is active),? #

# the functionality will be active.? ? ? ? ? ? ? ? ? ? ? ? ? ? #

#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

# Values set in Modules cannot be reloaded using the? ? ? ? ? ? #

# reloadproperties variable.? Once they are loaded, they remain #

# in memory until the application is restarted.? ? ? ? ? ? ? ? #

#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

#################################################################

#第一:module.log的屬性必須配置,如果不配置,P6SPY將不起任何作用,典型配置:

module.log=com.p6spy.engine.logging.P6LogFactory

#module.outage=com.p6spy.engine.outage.P6OutageFactory

#################################################################

# REALDRIVER(s)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

# In your application server configuration file you replace the #

# "real driver" name with com.p6spy.engine.P6SpyDriver. This is #

# where you put the name of your real driver P6Spy can find and #

# register your real driver to do the database work.? ? ? ? ? ? #

#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

# If your application uses several drivers specify them in? ? ? #

# realdriver2, realdriver3\.? See the documentation for more? ? #

# details.? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

# Values set in REALDRIVER(s) cannot be reloaded using the? ? ? #

# reloadproperties variable.? Once they are loaded, they remain #

# in memory until the application is restarted.? ? ? ? ? ? ? ? #

#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #

#################################################################

#第二:數(shù)據(jù)庫驅(qū)動配置,你懂的,不多說了

# 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

# the mysql open source driver

realdriver=org.gjt.mm.mysql.Driver

#specifies another driver to use

realdriver2=

#specifies a third driver to use

realdriver3=

#第三:appender配置,一般分為三種

#specifies the appender to use for logging

#appender=com.p6spy.engine.logging.appender.Log4jLogger

#控制臺

#appender=com.p6spy.engine.logging.appender.StdoutLogger

appender=com.p6spy.engine.logging.appender.FileLogger

# name of logfile 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? ? = spy.log

# append to? the p6spy log file.? if this is set to false the

# log file is truncated every time.? (file logger only)

append=true

#The following are for log4j logging 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.logger.p6spy=INFO,STDOUT

作者:Crazy_Coder

鏈接:http://www.itdecent.cn/p/199d5f78aa66

來源:簡書

簡書著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請聯(lián)系作者獲得授權(quán)并注明出處。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在應(yīng)用程序中添加日志記錄總的來說基于三個目的:監(jiān)視代碼中變量的變化情況,周期性的記錄到文件中供其他應(yīng)用進行統(tǒng)計分析...
    時待吾閱讀 5,158評論 0 6
  • 在應(yīng)用程序中添加日志記錄總的來說基于三個目的:監(jiān)視代碼中變量的變化情況,周期性的記錄到文件中供其他應(yīng)用進行統(tǒng)計分析...
    時待吾閱讀 5,215評論 1 13
  • 一、Log4j簡介 Log4j有三個主要的組件:Loggers(記錄器),Appenders (輸出源)和Layo...
    默默守護閱讀 1,978評論 2 8
  • from:https://www.cnblogs.com/ITtangtang/p/3926665.html一、L...
    enshunyan閱讀 3,410評論 0 0
  • protocol OMPDataPickerViewDelegate: NSObjectProtocol {} i...
    flionel閱讀 263評論 0 0

友情鏈接更多精彩內(nèi)容