psmith 2003/12/09 18:40:47 Modified: src/java/org/apache/log4j/pattern PatternParser.java Added: src/java/org/apache/log4j/pattern PropertiesPatternConverter.java Log: Added a Properties pattern converter by basically copying the MDCPropertyPatternConverter by Ceki. Since MDC uses the 'X', figured 'Y' was ok for properties, but also registered the word 'properties' as well. Revision Changes Path 1.8 +5 -0 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- PatternParser.java 23 Sep 2003 18:52:51 -0000 1.7 +++ PatternParser.java 10 Dec 2003 02:40:47 -0000 1.8 @@ -71,6 +71,7 @@ @author James P. Cakalic @author Ceki Gülcü @author Anders Kristensen + @auther Paul Smith @since 0.8.2 */ @@ -126,6 +127,10 @@ globalRulesRegistry.put("X", MDCPatternConverter.class.getName()); globalRulesRegistry.put("mdc", MDCPatternConverter.class.getName()); + + globalRulesRegistry.put("Y", PropertiesPatternConverter.class.getName()); + globalRulesRegistry.put("properties", PropertiesPatternConverter.class.getName()); + } int state; 1.1 jakarta-log4j/src/java/org/apache/log4j/pattern/PropertiesPatternConverter.java Index: PropertiesPatternConverter.java =================================================================== /* */ package org.apache.log4j.pattern; import org.apache.log4j.spi.LoggingEvent; import java.util.*; /** * Able to handle the contents of the LoggingEvent's Property bundle and either * output the entire contents of the properties in a similar format to the java.util.Hashtable.toString() * , or to output the value of a specific key within the property bundle * when this pattern converter has the option set. * * @author Paul Smith (but totally based (i.e 'copied') on the MDCPatternConverter by Ceki Gülcü) * with only minor alterations * */ public class PropertiesPatternConverter extends PatternConverter { public StringBuffer convert(LoggingEvent event) { StringBuffer buf = new StringBuffer(32); /** * if there is no additional options, we output every single * Key/Value pair for the MDC in a similar format to Hashtable.toString() */ if (option == null) { buf.append("{"); Set keySet = event.getPropertyKeySet(); for (Iterator i = keySet.iterator(); i.hasNext();) { Object item = i.next(); Object val = event.getProperty(item.toString()); buf.append("{").append(item).append(",").append(val).append( "}"); } buf.append("}"); return buf; } /** * otherwise they just want a single key output */ Object val = event.getProperty(option); if (val != null) { return buf.append(val); } return buf; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]