psmith 2003/12/10 14:06:51 Modified: src/java/org/apache/log4j/pattern PatternParser.java src/java/org/apache/log4j PatternLayout.java Added: src/java/org/apache/log4j/pattern ThrowableInformationPatternConverter.java Log: Added a ThrowableInformationPatternConverter to output the stack trace. Revision Changes Path 1.9 +1 -1 jakarta-log4j/src/java/org/apache/log4j/pattern/PatternParser.java Index: PatternParser.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/pattern/PatternParser.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- PatternParser.java 10 Dec 2003 02:40:47 -0000 1.8 +++ PatternParser.java 10 Dec 2003 22:06:51 -0000 1.9 @@ -128,8 +128,8 @@ globalRulesRegistry.put("X", MDCPatternConverter.class.getName()); globalRulesRegistry.put("mdc", MDCPatternConverter.class.getName()); - globalRulesRegistry.put("Y", PropertiesPatternConverter.class.getName()); globalRulesRegistry.put("properties", PropertiesPatternConverter.class.getName()); + globalRulesRegistry.put("throwable", ThrowableInformationPatternConverter.class.getName()); } 1.1 jakarta-log4j/src/java/org/apache/log4j/pattern/ThrowableInformationPatternConverter.java Index: ThrowableInformationPatternConverter.java =================================================================== /* * ============================================================================ * The Apache Software License, Version 1.1 * ============================================================================ * * Copyright (C) 1999 The Apache Software Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. The end-user documentation included with the redistribution, if any, must * include the following acknowledgment: "This product includes software * developed by the Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, if * and wherever such third-party acknowledgments normally appear. * * 4. The names "log4j" and "Apache Software Foundation" must not be used to * endorse or promote products derived from this software without prior * written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", nor may * "Apache" appear in their name, without prior written permission of the * Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This software consists of voluntary contributions made by many individuals * on behalf of the Apache Software Foundation. For more information on the * Apache Software Foundation, please see <http://www.apache.org/>. * */package org.apache.log4j.pattern; import org.apache.log4j.spi.LoggingEvent; import org.apache.log4j.spi.ThrowableInformation; /** * 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. * * @author Paul Smith * @since 1.3 * */ public class ThrowableInformationPatternConverter extends PatternConverter { /* (non-Javadoc) * @see org.apache.log4j.pattern.PatternConverter#convert(org.apache.log4j.spi.LoggingEvent) */ protected StringBuffer convert(LoggingEvent event) { StringBuffer buf = new StringBuffer(32); ThrowableInformation information = event.getThrowableInformation(); if (information == null) { return buf; } String[] stringRep = information.getThrowableStrRep(); int length = 0; if (getOption() == null) { length = stringRep.length; } else if (getOption().equals("full")) { length = stringRep.length; } else if (getOption().equals("short")) { length = 1; } else { length = stringRep.length; } for (int i = 0; i < length; i++) { String string = stringRep[i]; buf.append(string).append("\n"); } return buf; } } 1.27 +15 -5 jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java Index: PatternLayout.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- PatternLayout.java 10 Dec 2003 21:35:06 -0000 1.26 +++ PatternLayout.java 10 Dec 2003 22:06:51 -0000 1.27 @@ -310,18 +310,28 @@ </tr> <tr> - <td align=center><b>Y</b></td> + <td align=center><b>properties</b></td> <td> - <p>Used to output the Properties associated - with the logging event. The <b>Y</b> - conversion character can be followed by the key for the - map placed between braces, as in <b>%Y{application}</b> where + with the logging event. The <b>properties</b> + conversion word can be followed by the key for the + map placed between braces, as in <b>%properties{application}</b> where <code>application</code> is the key. The value in the Properties bundle corresponding to the key will be output. If no additional sub-option is specified, then the entire contents of the Properties key value pair set is output using a format {{key1,val1},{key2,val2}}</p> + </td> + </tr> + + <tr> + <td align=center><b>throwable</b></td> + + <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.</p> </td> </tr>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]