You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2010/05/17 06:13:32 UTC
svn commit: r944960 - in /logging/log4j/companions/extras/trunk/src:
changes/ main/java/org/apache/log4j/ main/java/org/apache/log4j/helpers/
main/java/org/apache/log4j/pattern/
Author: carnold
Date: Mon May 17 04:13:32 2010
New Revision: 944960
URL: http://svn.apache.org/viewvc?rev=944960&view=rev
Log:
Bug 48902: Add %throwable{n} pattern
Modified:
logging/log4j/companions/extras/trunk/src/changes/changes.xml
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/EnhancedPatternLayout.java
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/helpers/MDCKeySetExtractor.java
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/CachedDateFormat.java
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/PropertiesPatternConverter.java
logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java
Modified: logging/log4j/companions/extras/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/changes/changes.xml?rev=944960&r1=944959&r2=944960&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/changes/changes.xml (original)
+++ logging/log4j/companions/extras/trunk/src/changes/changes.xml Mon May 17 04:13:32 2010
@@ -33,6 +33,7 @@
<action action="fix" issue="48911">LogMF did not optimize simple patterns on multiple parameter log requests.</action>
<action action="fix" issue="48927">EnhancedPatternLayout tests conflict with PatternLayout tests.</action>
<action action="add" issue="49010">Add %p{-2} pattern to EnhancedPatternLayout to drop two leading elements from name.</action>
+ <action action="add" issue="48902">Add %throwable{n} and {-n} pattern to EnhancedPatternLayout to print n or drop last n lines.</action>
</release>
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/EnhancedPatternLayout.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/EnhancedPatternLayout.java?rev=944960&r1=944959&r2=944960&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/EnhancedPatternLayout.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/EnhancedPatternLayout.java Mon May 17 04:13:32 2010
@@ -286,11 +286,14 @@ import org.apache.log4j.spi.LoggingEvent
<td>
<p>Used to output the Throwable trace that has been bound to the LoggingEvent, by
- default this will output the full trace as one would normally find by a call to Throwable.printStackTrace().
- The throwable conversion word can be followed by an option in the form <b>%throwable{short}</b>
- which will only output the first line of the ThrowableInformation, or <b>%throwable{none}</b> which
- will suppress the stack trace. If no %throwable pattern is provided, the appender may provide its
- rendering of the exception.</p>
+ default this will output the full trace as one would normally
+ find by a call to Throwable.printStackTrace().
+ <b>%throwable{short}</b> or <b>%throwable{1}</b> will output the first line of
+ stack trace. <b>throwable{none}</b> or <b>throwable{0}</b> will suppress
+ the stack trace. <b>%throwable{n}</b> will output n lines of stack trace
+ if a positive integer or omit the last -n lines if a negative integer.
+ If no %throwable pattern is specified, the appender will take
+ responsibility to output the stack trace as it sees fit.</p>
</td>
</tr>
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/helpers/MDCKeySetExtractor.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/helpers/MDCKeySetExtractor.java?rev=944960&r1=944959&r2=944960&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/helpers/MDCKeySetExtractor.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/helpers/MDCKeySetExtractor.java Mon May 17 04:13:32 2010
@@ -20,7 +20,6 @@ import org.apache.log4j.spi.LoggingEvent
import org.apache.log4j.pattern.LogEvent;
import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/CachedDateFormat.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/CachedDateFormat.java?rev=944960&r1=944959&r2=944960&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/CachedDateFormat.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/CachedDateFormat.java Mon May 17 04:13:32 2010
@@ -35,6 +35,10 @@ import java.util.TimeZone;
*/
public final class CachedDateFormat extends DateFormat {
/**
+ * Serialization version.
+ */
+ private static final long serialVersionUID = 1;
+ /**
* Constant used to represent that there was no change
* observed when changing the millisecond count.
*/
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java?rev=944960&r1=944959&r2=944960&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/DatePatternConverter.java Mon May 17 04:13:32 2010
@@ -71,7 +71,11 @@ public final class DatePatternConverter
* default time zone before each format and parse request.
*/
private static class DefaultZoneDateFormat extends DateFormat {
- /**
+ /**
+ * Serialization version ID.
+ */
+ private static final long serialVersionUID = 1;
+ /**
* Wrapped instance of DateFormat.
*/
private final DateFormat dateFormat;
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/PropertiesPatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/PropertiesPatternConverter.java?rev=944960&r1=944959&r2=944960&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/PropertiesPatternConverter.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/PropertiesPatternConverter.java Mon May 17 04:13:32 2010
@@ -19,11 +19,6 @@ package org.apache.log4j.pattern;
import org.apache.log4j.spi.LoggingEvent;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.*;
import java.util.Iterator;
import java.util.Set;
import org.apache.log4j.helpers.*;
Modified: logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java?rev=944960&r1=944959&r2=944960&view=diff
==============================================================================
--- logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java (original)
+++ logging/log4j/companions/extras/trunk/src/main/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java Mon May 17 04:13:32 2010
@@ -22,18 +22,23 @@ import org.apache.log4j.spi.ThrowableInf
/**
- * Outputs the ThrowableInformation portion of the LoggingiEvent as a full stacktrace
- * unless this converter's option is 'short', where it just outputs the first line of the trace.
+ * Outputs the ThrowableInformation portion of the LoggingEvent.
+ * By default, outputs the full stack trace. %throwable{none}
+ * or %throwable{0} suppresses the stack trace. %throwable{short}
+ * or %throwable{1} outputs just the first line. %throwable{n}
+ * will output n lines for a positive integer or drop the last
+ * -n lines for a negative integer.
*
* @author Paul Smith
*
*/
public class ThrowableInformationPatternConverter
extends LoggingEventPatternConverter {
+
/**
- * If "short", only first line of throwable report will be formatted.
+ * Maximum lines of stack trace to output.
*/
- private final String option;
+ private int maxLines = Integer.MAX_VALUE;
/**
* Private constructor.
@@ -44,9 +49,16 @@ public class ThrowableInformationPattern
super("Throwable", "throwable");
if ((options != null) && (options.length > 0)) {
- option = options[0];
- } else {
- option = null;
+ if("none".equals(options[0])) {
+ maxLines = 0;
+ } else if("short".equals(options[0])) {
+ maxLines = 1;
+ } else {
+ try {
+ maxLines = Integer.parseInt(options[0]);
+ } catch(NumberFormatException ex) {
+ }
+ }
}
}
@@ -65,15 +77,17 @@ public class ThrowableInformationPattern
* {@inheritDoc}
*/
public void format(final LoggingEvent event, final StringBuffer toAppendTo) {
- if (!"none".equals(option)) {
+ if (maxLines != 0) {
ThrowableInformation information = event.getThrowableInformation();
if (information != null) {
String[] stringRep = information.getThrowableStrRep();
int length = stringRep.length;
- if ("short".equals(option)) {
- length = 1;
+ if (maxLines < 0) {
+ length += maxLines;
+ } else if (length > maxLines) {
+ length = maxLines;
}
for (int i = 0; i < length; i++) {
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org