Hello,
yesterday I used the PatternLayout and I wanted to disable the
stacktrace output.
I couldn't find a possibility to do it by configuration.
In cause of that I've patched the ThrowableInformationPatternConverter.
Have a look at the attached patch.
Now you can use the following ConversionPatterns in your property file.
%d{dd MMM yy HH:mm:ss,SSS} |%p|%c{2}| %m %n %throwable{0} - no line of
throwable will be printed out
%d{dd MMM yy HH:mm:ss,SSS} |%p|%c{2}| %m %n %throwable{none} - no line
of throwable will be printed out
%d{dd MMM yy HH:mm:ss,SSS} |%p|%c{2}| %m %n %throwable{3} - three lines
ot throwable will be printed out
...
I hope you like the improvement and apply the patch.
With best regards,
Marcel.
Index:
src/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java
===================================================================
--- src/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java
(revision 507432)
+++ src/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java
(working copy)
@@ -22,8 +22,15 @@
/**
- * 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 as a full
stacktrace
+ * unless the converter's option isn't one of the following:</br>
+ * <ul>
+ * <li>short <i>- prints out the first line of the stacktrace</i></li>
+ * <li>none <i>- nothing of the stacktrace will be printed out</i></li>
+ * <li>2 <i>- prints out the first two lines of the stacktrace</i></li>
+ * <li>5 <i>- prints out the first five lines of the stacktrace</i></li>
+ * <li>"digit" <i>- prints out as many lines of the stacktrace as
specified by digit</i></li>
+ * </ul>
*
* @author Paul Smith
* @since 1.3
@@ -33,6 +40,8 @@
extends LoggingEventPatternConverter {
/**
* If "short", only first line of throwable report will be formatted.
+ * If "none", no line of throwable report will be formatted.
+ * If any digit, the value specifies the number of lines of the throwable
report.
*/
private final String option;
@@ -81,8 +90,17 @@
length = stringRep.length;
} else if (option.equals("short")) {
length = 1;
+ } else if (option.equals("none")) {
+ length = 0;
} else {
- length = stringRep.length;
+ final int numberOfLines = Integer.valueOf(option);
+ if (numberOfLines < 0) {
+ length = stringRep.length;
+ } else if (numberOfLines > stringRep.length) {
+ length = stringRep.length;
+ } else {
+ length = numberOfLines;
+ }
}
for (int i = 0; i < length; i++) {
Index: src/java/org/apache/log4j/PatternLayout.java
===================================================================
--- src/java/org/apache/log4j/PatternLayout.java (revision 507432)
+++ src/java/org/apache/log4j/PatternLayout.java (working copy)
@@ -19,6 +19,7 @@
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.helpers.PatternConverter;
import org.apache.log4j.pattern.BridgePatternConverter;
+import org.apache.log4j.pattern.ThrowableInformationPatternConverter;
import org.apache.log4j.spi.LoggingEvent;
@@ -279,7 +280,8 @@
<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.</p>
+ which will only output the first line of the ThrowableInformation.
+ See [EMAIL PROTECTED] ThrowableInformationPatternConverter} for more
option details.</p>
</td>
</tr>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]