How do I configure Logback to ignore logging on exceptions of a particular type?
相关问题
- slurm: use a control node also for computing
- how to call a C++ dll from C# windows application
- I want to trace logs using a Macro multi parameter
- Error message 'No handlers could be found for
- convert logback.xml to log4j.properties
相关文章
- how do I log requests and responses for debugging
- JUnit continue to assert things after expected exc
- Android Studio doesn't display logs by package
- How to handle translation of exception message?
- correct way to store an exception in a variable
- Stacktrace does not print in Glassfish 4.1 Cluster
- UnhandledException Event doesn't work?
- Out of curiosity — why don't logging APIs impl
You can do it with a simple
EvaluatorFilter
:Please note that you need the following dependency in your
pom.xml
as well:Another possible solution is a custom
Filter
implementation:With a proper config:
In a
TurboFilter
you get the thrownThrowable
instance directly, so you can call theisInstance
method without manually casting theIThrowableProxy
toThrowableProxy
.Further documentation
This question is 5 years old, but I'm supplying the solution I found just to keep it up to date.
I found a solution in the offical docs: http://logback.qos.ch/manual/layouts.html
For my particular situation, which is a 17 year old web site running plain old servlets (ah, the days), the servlet is now throwing an exception if the user was not logged in. So here's my code snippets:
Servlet
web.xml
From the setup above, I didn't want to log this exception as it's not really an exception, but rather a break in logic to redirect to login.
So, the start of my logback.xml file is this:
and further down in the logback.xml file, my appenders:
Also note, in order to this work, I had to include janino to handle the expression parsing.
This is an additional example of the response of @palacsint that apply when the error is not an exception using JaninoEventEvaluator: