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 ps...@apache.org on 2003/05/01 01:25:28 UTC
cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/xml XMLDecoder.java
psmith 2003/04/30 16:25:28
Modified: src/java/org/apache/log4j/xml XMLDecoder.java
Log:
Added a setAdditionProperties method to allow a map of properties
to be appended to each event as it is decoded, and modified
the decode method to actually do the adding of these properties.
Revision Changes Path
1.3 +31 -0 jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLDecoder.java
Index: XMLDecoder.java
===================================================================
RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/xml/XMLDecoder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLDecoder.java 30 Apr 2003 04:19:36 -0000 1.2
+++ XMLDecoder.java 30 Apr 2003 23:25:27 -0000 1.3
@@ -54,7 +54,10 @@
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.StringReader;
+import java.util.Collections;
import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Vector;
import javax.xml.parsers.DocumentBuilder;
@@ -88,6 +91,8 @@
private StringBuffer buf = new StringBuffer();
private DocumentBuilderFactory dbf;
private DocumentBuilder docBuilder;
+
+ private Map additionalProperties = Collections.EMPTY_MAP;
public XMLDecoder() {
dbf = DocumentBuilderFactory.newInstance();
@@ -101,6 +106,18 @@
System.err.println("Unable to get document builder");
}
}
+
+ /**
+ * Sets an additionalProperty map, where each Key/Value pair is
+ * automatically added to each LoggingEvent as it is decoded.
+ *
+ * This is useful, say, to include the source file name of the Logging events
+ * @param additionalProperties
+ */
+ public void setAdditionalProperties(Map additionalProperties)
+ {
+ this.additionalProperties = additionalProperties;
+ }
/**
* Converts the LoggingEvent data in XML string format into an actual
@@ -318,6 +335,20 @@
}
}
}
+
+ /**
+ * We add all the additional properties to the properties
+ * hashtable
+ */
+ if (additionalProperties.size()>0) {
+ if (properties == null) {
+ properties = new Hashtable(additionalProperties);
+ }
+ else {
+ properties.putAll(additionalProperties);
+ }
+ }
+
}
events.add(new LoggingEvent(
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org