This is how I did it some months ago (don't know if there's a more elegant
solution to this ;)

Basically, extend the PatternLayout (or whatever Layout you want to use
without stack traces) and
override the "ignoresThrowable()" method to make it return false - that
makes log4j think that your Layout will
indeed do something nice with the Throwable stack trace. Fact is, you don't,
so stack traces don't get shown.
Use this layout with the appenders you don't want stack traces in.

You could get fancier and change that false for a configurable field with a
getter and a setter - that way you can
alter in the log4j configuration if you want the stack traces or not.

*
public* *class* NoStackTracePatternLayout *extends* PatternLayout {
    ***public* *boolean* ignoresThrowable() {
        *return* false;
    }
**}


On 2/16/06, Mark <[EMAIL PROTECTED]> wrote:
>
> Is there a way to prevent stack traces from being placed in log files?
> I guess the obvious would be to not pass Throwable objects to Log4J,
> but is there another solution?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


--
Javier González Nicolini

Reply via email to