Pretty much everything in the question. I just discovered p6spy in association with hibernate which is really cool to see the actual sql queries, though I'm quite baffled on how it works.
So how does it work?  
            Asked
            
        
        
            Active
            
        
            Viewed 3,231 times
        
    1 Answers
3
            
            
        the basic idea on p6spy goes like this:
- depending if you go for 
Datasourceor forJDBC driverin your code, what you do is instead of referring the real ones, you specify p6spy specific ones:com.p6spy.engine.spy.P6SpyDriverorcom.p6spy.engine.spy.P6DataSourcerespectively (for full documentation, see: p6spy.readthedocs.io/en/latest/configandusage.html). - afterwards you configure the real ones in your 
spy.propertiesfile (usingrealdriverorrealdatasourceproperties respectively) - depending on the configuration you can achieve the logging of sql statements (using 
com.p6spy.engine.logging.P6LogFactory) - so to answer your question, the idea is that all the jdbc calls (statements execution, transaction related stuff) will be wrapped (proxied) by p6spy and depending on your configuration, these can be logged via the file logger (using 
appender=com.p6spy.engine.logging.appender.FileLogger), stdout logger (usingappender=com.p6spy.engine.logging.appender.StdoutLogger) or log4j logger (using:appender=com.p6spy.engine.logging.appender.Log4jLogger) 
If interested in more details, feel free to ask, or check the project itself on: https://github.com/p6spy/p6spy
        Daniel Käfer
        
- 4,458
 - 3
 - 32
 - 41
 
        Peter Butkovic
        
- 11,143
 - 10
 - 57
 - 81