I want to filter out certain lines from stack traces using log4j (like net.sf.cglib.*
and org.springframework.*
). Is it possible to configure this with log4j
?
In eclipse the junit plugin allows you to add filters which modify the stack traces displayed in the junit tab, but this doesn't change the stack traces output to the console.
Analyze external stack tracesFrom the main menu, select Code | Analyze Stack Trace or Thread Dump. In the Analyze Stack Trace dialog that opens, paste the external stack trace or thread dump into the Put a stacktrace here: text area. Click OK. The stack trace is displayed in the Run tool window.
Filters allow Log Events to be evaluated to determine if or how they should be published. A Filter will be called on one of its filter methods and will return a Result, which is an Enum that has one of 3 values - ACCEPT, DENY or NEUTRAL.
The stack trace, also called a backtrace, consists of a collection of stack records, which store an application's movement during its execution. The stack trace includes information about program subroutines and can be used to debug or troubleshoot and is often used to create log files.
The first line in the call stack represents the last executed function call, so remember to always read a stack trace top-down.
Use this filtering layout log4j add-on: http://www.openmindlab.com/lab/tools/openutilslog4j/layout.html
They have an example with log4j.xml on that page. Just use the it.openutils.log4j.FilteredPatternLayout instead of the log4j PatternLayout, and then put some entries like
<param name="Filter" value="net.sf.cglib"/>
<param name="Filter" value="org.springframework"/>
below.
I just published an Open Source library that filters the stacktrace very nicely. Here is the link to a short article about the library: MgntUtils Open Source Java Library Also here is a github link to the sources: https://github.com/michaelgantman/Mgnt and here is Maven link to the library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With