Is possible to add a filter by message in my logback config?
I am using a tool which logs the SQL statements generated by Hibernate: https://stackoverflow.com/a/19299769/5033118
I overwrite the logback configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>%msg%n</Pattern>
</encoder>
</appender>
<logger name="jdbc.audit" level="ERROR" />
<logger name="jdbc.connection" level="ERROR" />
<logger name="jdbc.sqltiming" level="ERROR" />
<logger name="jdbc.resultset" level="ERROR" />
<logger name="jdbc.resultsettable" level="ERROR" />
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
The tool logs the statements, but it also logs some other messages:
1. PreparedStatement.new PreparedStatement returned
1. Connection.prepareStatement(delete from AIXM_FEATURE_EVENT_MAPPING where TS_ID=?) returned net.sf.log4jdbc.sql.jdbcapi.PreparedStatementSpy@4aab04cf
1. PreparedStatement.setString(1, "3b855115-2da2-495c-a3bf-b2328916ef77") returned
1. delete from AIXM_FEATURE_EVENT_MAPPING where TS_ID='3b855115-2da2-495c-a3bf-b2328916ef77' {executed in 38 ms}
1. PreparedStatement.executeUpdate() returned 0
1. PreparedStatement.getMaxRows() returned 0
1. PreparedStatement.getQueryTimeout() returned 0
1. PreparedStatement.close() returned
What I am trying to do is to add a filter in my logback configuration to get ONLY the SQL statements (and to format them if possible - remove the "1. " from the start of the line and add a ";" at the end).
delete from AIXM_FEATURE_EVENT_MAPPING where TS_ID='3b855115-2da2-495c-a3bf-b2328916ef77';