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 Wed, 23 Apr 2008 22:19:04 GMT
Okay, I'm assuming that somewhere this exception is passed to log4j in  
something like:

try {
      ///
} catch(Exception ex) {
     logger.info("Some app message", ex);
}

Using a standard layout, the stack trace will get rendered by  
WriterAppender.subAppend.

     this.qw.write(this.layout.format(event));

     if(layout.ignoresThrowable()) {
       String[] s = event.getThrowableStrRep();
       if (s != null) {
	int len = s.length;
	for(int i = 0; i < len; i++) {
	  this.qw.write(s[i]);
	  this.qw.write(Layout.LINE_SEP);
	}
       }
     }


Most appenders will return ignoreThrowable to true which will result  
in org.apache.log4j.spi.LoggingEvent;getThrowableStrRep() to render  
the exception which will eventually end up at  
org.apache.log4j.spi.ThrowableInformation.getThrowableStrRep() which  
will then call the printStackTrace() method of the exception.  The  
SymSQLException.printStackTrace() implementation (or the underlying  
JVM) is most likely the source of the ".. 14 more".

At least as I understand the situation, OnlyOnceErrorHandler would not  
be involved.  It would only be involved if the appender was raising  
exceptions and you mentioned using a FileAppender and a file appender  
should not be raising SQL exceptions.

A custom object renderer would not be useful unless the exception was  
used as the message parameter, which is probably not the case.

The best way to add a custom rendering of the stack trace would be to  
write a custom appender (likely either wrapping or extending  
PatternLayout) which returns false ignoresThrowable() and then appends  
your custom equivalent to printStackTrace() the the result of the  
PatternLayout.format.



On Apr 23, 2008, at 3:28 PM, Matthew Kemp wrote:

> You can create your own custom object renderer that will properly  
> render the
> whole stack trace. This renderer will need to be included in the log4j
> config and be available on the classpath when log4j initializes.
>
>
> On Wed, Apr 23, 2008 at 3:19 PM, Robert Pepersack <
> RPepersack@mdinsurance.state.md.us> wrote:
>
>> Hello,
>>
>> I'm using FileAppender to log to a log file.  When an exception gets
>> caught and printed, the stack trace is truncated as it usually is by
>> default:
>>
>> Caused by: com.sybase.jdbc3.jdbc.SybSQLException: Attempt to insert  
>> NULL
>> value into column 'id', table 'table'; column does not allow nulls.  
>> Update
>> fails.
>>
>>       at com.sybase.jdbc3.tds.Tds.a(Unknown Source)
>>       at com.sybase.jdbc3.tds.Tds.nextResult(Unknown Source)
>>       at com.sybase.jdbc3.jdbc.ResultGetter.nextResult(Unknown  
>> Source)
>>       at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown  
>> Source)
>>       at com.sybase.jdbc3.jdbc.SybStatement.nextResult(Unknown  
>> Source)
>>       at com.sybase.jdbc3.jdbc.SybStatement.queryLoop(Unknown Source)
>>       at  
>> com.sybase.jdbc3.jdbc.SybCallableStatement.executeQuery(Unknown
>> Source)
>>       at miaJs.jdbc.JdbcFacade.executeQuery(JdbcFacade.java:977)
>>       ... 14 more
>>
>> Instead of  the "... 14 more" at the bottom, I would like to see the
>> entire stack trace.  I know how to get Java to do this by using
>> Throwable.getStackTrace(), and then loop through the array of
>> StackTraceElements.  I looked in the log4j source code.  I think that
>> FileAppender uses the OnlyOnceErrorHandler in its super, superclass
>> AppenderSkeleton.  It looks like OnlyOnceErrorHandler uses LogLog.   
>> But, I'm
>> not sure how to get log4j to print the entire stack trace.
>>
>> Thanks,
>>
>> Bob
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>>
>>


---------------------------------------------------------------------
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