logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: FileAppender Truncates Stack Trace
Date Thu, 24 Apr 2008 16:08:04 GMT

On Apr 24, 2008, at 8:04 AM, Robert Pepersack wrote:

> Thanks for your reply.
>
> I've seen this behavior with many different exception classes, so I  
> think it's the VM.
>
> I've written a couple of appenders before.  For example, I wrote a  
> SystemOutAppender that solves this problem when printing to the  
> console.  The source code for SystemOutAppender is below.  How would  
> I adapt this to work as DailyRollingFileAppender and FileAppender?
>


As I mentioned in my original post, the right place to address this is  
in the Layout.  Something like:

package com.example.logging;

public class PatternLayout extends org.apache.log4j.PatternLayout {
     public PatternLayout() {
     }

     public String format(final LoggingEvent event) {
          String msg = super.format(event);
          ThrowableInformation throwInfo =  
event.getThrowableInformation();
          if (throwInfo == null) {
               return msg;
          } else {
                 StringBuffer buf = new StringBuffer(msg);
                 buf.append(Layout.LINE_SEP);
		Throwable throwable = throwInfo.getThrowable();
                 //
                 //   deserialized LoggingEvents would be missing  
throwable
                 //      so just output their previously captured  
stack trace
                 if (throwable == null) {
                      String[] rendered =  
throwInfo.getThrowableStrRep();
                      for(int  i = 0; i < rendered.length; i++) {
                            buf.append(rendered[i]);
                            buf.append(Layout.LINE_SEP);
                      }
                 } else {
                      //
                      //     your stack trace code goes here
                      //
                 }
	        return buf.toString();
          }
      }

     public boolean ignoresThrowable() {
         return false;
    }
}

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


Mime
View raw message