You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Mark <el...@gmail.com> on 2006/02/16 21:04:04 UTC

preventing stack traces in log files

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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: preventing stack traces in log files

Posted by paul womack <pw...@papermule.co.uk>.
Javier Gonzalez wrote:
> 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.

In this vein, I created an extended PatternLayout that added %s and %S
conversion characters; these gace "short" and "full" stack trace in
the output, if used.

    BugBear

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: preventing stack traces in log files

Posted by Javier Gonzalez <ja...@gmail.com>.
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 <el...@gmail.com> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


--
Javier González Nicolini

Re: preventing stack traces in log files

Posted by James Stauffer <st...@gmail.com>.
I think the ConversionPattern determines if it is included.  I thought
that removing ending "%n" took care of it.  (I haven't tested and am
not sure).

On 2/16/06, Mark <el...@gmail.com> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


--
James Stauffer
Are you good? Take the test at http://www.livingwaters.com/good/

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org