Only show effective SQL string P6Spy

p6spy, sql

Solution

In spy.properties there is a property called `logMessageFormat` that you can set to a custom implementation of `MessageFormattingStrategy`. This works for any type of logger (i.e. file, slf4j etc.).

E.g.

logMessageFormat=my.custom.PrettySqlFormat

An example using Hibernate's pretty-printing SQL formatter:

package my.custom;

import org.hibernate.jdbc.util.BasicFormatterImpl;
import org.hibernate.jdbc.util.Formatter;

import com.p6spy.engine.spy.appender.MessageFormattingStrategy;

public class PrettySqlFormat implements MessageFormattingStrategy {

    private final Formatter formatter = new BasicFormatterImpl();

    @Override
    public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql) {
        return formatter.format(sql); 
    }

}

Problem

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!

Original source