ça fait le même boulot que p6spy sauf que tu dois coder les classes de debug.
p6spy est assez simple, tu as un fichier de config spy.properties présent dans le classpath :
#################################################################
# P6Spy Options File #
# See documentation for detailed instructions #
#################################################################
module.log=com.p6spy.engine.logging.P6LogFactory
#module.outage=com.p6spy.engine.outage.P6OutageFactory
# the mysql open source driver
realdriver=com.mysql.jdbc.Driver
deregisterdrivers = true
################################################################
# P6OUTAGE SPECIFIC PROPERTIES #
################################################################
# Outage Detection
#
# This feature detects long-running statements that may be indicative of
# a database outage problem. If this feature is turned on, it will log any
# statement that surpasses the configurable time boundary during its execution.
# When this feature is enabled, no other statements are logged except the long
# running statements. The interval property is the boundary time set in seconds.
# For example, if this is set to 2, then any statement requiring at least 2
# seconds will be logged. Note that the same statement will continue to be logged
# for as long as it executes. So if the interval is set to 2, and the query takes
# 11 seconds, it will be logged 5 times (at the 2, 4, 6, 8, 10 second intervals).
#
# outagedetection=true|false
# outagedetectioninterval=integer time (seconds)
#
outagedetection=false
outagedetectioninterval=
################################################################
# COMMON PROPERTIES #
################################################################
# filter what is logged
filter=false
# comma separated list of tables to include when filtering
include =
# comma separated list of tables to exclude when filtering
exclude =
# sql expression to evaluate if using regex filtering
sqlexpression =
# turn on tracing
autoflush = true
# sets the date format using Java's SimpleDateFormat routine
dateformat=
#list of categories to explicitly include
includecategories=statement,batch,commit,rollback,info,error,result
#list of categories to exclude: error, info, batch, debug, statement,
#commit, rollback and result are valid values
#excludecategories=info,debug,result,batch
excludecategories=debug
#allows you to use a regex engine 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 every statement logged
stacktrace=false
# if stacktrace=true, specifies the stack trace to print
stacktraceclass=
# determines if property file should be reloaded
reloadproperties=false
# determines how often should be reloaded in seconds
reloadpropertiesinterval=60
#if=true then url must be prefixed with p6spy:
useprefix=false
#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 = FILE
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=p6spy - %d{ABSOLUTE} - %p %c - %m%n
log4j.logger.p6spy=STDOUT
log4j.additivity.p6spy=false
dont la seule valeur à modifier est la propriété realdriver. Après tu peux aussi modifier la config de log4j si tu veux.
Ensuite dans ton code/config de datasource, tu références le driver de p6spy com.p6spy.engine.spy.P6SpyDriver.
Tu ajoutes le jar dans ton classpath et c'est parti