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耗時(shí): %(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

# 實(shí)際驅(qū)動(dòng)

driverlist=com.mysql.jdbc.Driver

# 是否開啟慢SQL記錄

outagedetection=true

# 慢SQL記錄標(biāo)準(zhǔn) 秒

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.reibang.com/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ū)動(dòng)配置,你懂的似谁,不多說了

# 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

#控制臺(tái)

#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.reibang.com/p/199d5f78aa66

來源:簡(jiǎn)書

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

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末秃诵,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子塞琼,更是在濱河造成了極大的恐慌菠净,老刑警劉巖,帶你破解...
    沈念sama閱讀 212,718評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件彪杉,死亡現(xiàn)場(chǎng)離奇詭異毅往,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)派近,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,683評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門攀唯,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人渴丸,你說我怎么就攤上這事侯嘀。” “怎么了谱轨?”我有些...
    開封第一講書人閱讀 158,207評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵戒幔,是天一觀的道長。 經(jīng)常有香客問我碟嘴,道長溪食,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,755評(píng)論 1 284
  • 正文 為了忘掉前任娜扇,我火速辦了婚禮错沃,結(jié)果婚禮上栅组,老公的妹妹穿的比我還像新娘。我一直安慰自己枢析,他們只是感情好玉掸,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,862評(píng)論 6 386
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著醒叁,像睡著了一般司浪。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上把沼,一...
    開封第一講書人閱讀 50,050評(píng)論 1 291
  • 那天啊易,我揣著相機(jī)與錄音,去河邊找鬼饮睬。 笑死租谈,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的捆愁。 我是一名探鬼主播割去,決...
    沈念sama閱讀 39,136評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼昼丑!你這毒婦竟也來了呻逆?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,882評(píng)論 0 268
  • 序言:老撾萬榮一對(duì)情侶失蹤菩帝,失蹤者是張志新(化名)和其女友劉穎咖城,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體呼奢,經(jīng)...
    沈念sama閱讀 44,330評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡酒繁,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,651評(píng)論 2 327
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了控妻。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,789評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡揭绑,死狀恐怖弓候,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情他匪,我是刑警寧澤菇存,帶...
    沈念sama閱讀 34,477評(píng)論 4 333
  • 正文 年R本政府宣布,位于F島的核電站邦蜜,受9級(jí)特大地震影響依鸥,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜悼沈,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,135評(píng)論 3 317
  • 文/蒙蒙 一贱迟、第九天 我趴在偏房一處隱蔽的房頂上張望姐扮。 院中可真熱鬧,春花似錦衣吠、人聲如沸茶敏。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,864評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽惊搏。三九已至,卻和暖如春忧换,著一層夾襖步出監(jiān)牢的瞬間恬惯,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,099評(píng)論 1 267
  • 我被黑心中介騙來泰國打工亚茬, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留酪耳,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,598評(píng)論 2 362
  • 正文 我出身青樓才写,卻偏偏與公主長得像葡兑,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子赞草,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,697評(píng)論 2 351

推薦閱讀更多精彩內(nèi)容

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