I have a "Duplicate entry" exception, which logging SqlExceptionHelper
. I need to disable logging only this exception. How can I do it?
Asked
Active
Viewed 8,646 times
7

Squeez
- 919
- 2
- 12
- 30
3 Answers
7
I am assuming you are using Log4j for your logging. You may want to explore ExpressionFilter
.
I am appending a sample configuration, you can take it from there, hopefully.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="CONSOLE">
<param name="Target" value="System.out"/>
<layout>
<param name="ConversionPattern" value="%d %p [%c] - %m%n"/>
</layout>
<filter class="org.apache.log4j.filter.ExpressionFilter">
<param name="expression" value="EXCEPTION ~= SqlExceptionHelper" />
<param name="acceptOnMatch" value="false"/>
</filter>
</appender>
<root>
<priority value ="INFO" />
<appender-ref ref="CONSOLE"/>
</root>
</log4j:configuration>

informatik01
- 16,038
- 10
- 74
- 104

user1933888
- 2,897
- 3
- 27
- 36
-
I can filter by text, or only by class? – Squeez Aug 26 '15 at 09:10
-
http://logging.apache.org/log4j/companions/apidocs/org/apache/log4j/filter/ExpressionFilter.html – user1933888 Aug 26 '15 at 09:13
2
If you are using log4j2
<Logger name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper" level="OFF" additivity="false">
<AppenderRef ref="Console" />
</Logger>

abbas
- 6,453
- 2
- 40
- 36
-7
You can catch the exception and do nothing
try {
method();
} catch(ConstraintViolationException e){}

Bruno Caceiro
- 7,035
- 1
- 26
- 45
-
This exception throws in hibernate's saveOrUpdate method. I catch it later. – Squeez Aug 26 '15 at 09:07
-
3