I'm using p6spy to log the sql statements generated by my program. The format for the outputted spy.log file looks like this:
current time|execution time|category|statement SQL String|effective SQL string
I'm just wondering if anyone knows if there's a way to alter the spy.properties file and have only the last column, the effective SQL string, output to the spy.log file? I've looked through the properties file but haven't found anything that seems to support this.
Thanks!
I agree with @boberj, we are used to having logs with Hibernate formatter, but don't forget about batching, that's why I suggest to use:
There is no such option provided to achieve it via configuration only yet. I think you have 2 options here:
For the later option, I believe you could achieve it via your own class (depending on the logger you use, let's assume you use Log4jLogger).
Well, if you check relevant part of the Log4jLogger github as well as sourceforge version, your implementation should be rather straightforward:
spy.properties:
Implementation itself could look like this:
Please note the implementation should cover github (new project home, no version released yet) as well as sourceforge (original project home, released 1.3 version).
Please note: I didn't test the proposal myself, but it could be a good starting point and from the code review itself I'd say it could work.
You can patch
com.p6spy.engine.spy.appender.SingleLineFormat.java
removing the prepared element and any reference to P6Util like so:Then compile just the file
javac com.p6spy.engine.spy.appender.SingleLineFormat.java
And replace the existing class file in p6spy.jar with the new one.
In spy.properties there is a property called
logMessageFormat
that you can set to a custom implementation ofMessageFormattingStrategy
. This works for any type of logger (i.e. file, slf4j etc.).E.g.
An example using Hibernate's pretty-printing SQL formatter: