log4j - Omitting stack trace with ConsoleAppender

C

Christian Ashby

Is there any way to not display the stack trace in a console appender?

TIA,

Christian Ashby
Spiralinks, Inc.
 
O

Oscar kind

Christian Ashby said:
Is there any way to not display the stack trace in a console appender?

Not directly. You could however, do this:
- Log all messages to both a log file and the console.
- Give the console a threshold of "warn". This means the log statements
with a priority of "debug" and "info" will not be logged to the console.
- Log all stack traces using the "debug" priority.

This gives you greater controll over logging. It also makes sure you can
see in the console if the log file contains something you should take a
look at.

If you really want to log everything but stack traces to the console
however, you should create your own appender.
 
S

scott

Sure, don't use ConsoleAppender. Use log4j's Chainsaw V2 instead:

http://logging.apache.org/log4j/docs/chainsaw.html

Available via WebStart - click the 'launch' link on the page.

Chainsaw can parse and tail log files, accept events generated by
SocketAppender, process jdk1.4 (java.util.logging) events written to
file or socket, and much more.

To hide events in the UI that contain an exception, use this
expression in the 'refine focus' field:
! ( EXCEPTION EXISTS )

Conversely, to show only events with an exception, use this expression
in the 'refine focus' field:
EXCEPTION EXISTS

There is a tutorial available from the Welcome tab that generates
sample events and describes the expression syntax.

Feel free to post questions to the log4j-user mailing list:
http://logging.apache.org/site/mailing-lists.html

Scott
 
C

Christian Ashby

Sure, don't use ConsoleAppender. Use log4j's Chainsaw V2 instead:

I already do. The problem is that I'm in the middle of refactoring / code
sweeping / tidying, and migrating to Log4j (there's lots of code to go
through!); the old code just writes to system.out (it's a web application)

Thanks both of you for your answers though; it seems the quickest way to do
it is not put the exception object in code I don't want the stack traces to
appear for now (until I've cleaned up the code anyway!)

Christian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top