ceki 2004/05/09 12:15:03
Modified: tests/witness xmlLayout.mdc.1 patternLayout.mdc.1
xmlLayout.mdc.2 patternLayout.mdc.2
src/java/org/apache/log4j/spi LoggingEvent.java
src/java/org/apache/log4j/xml XMLLayout.java
Log:
Changes to ensure that all unit tests pass
Revision Changes Path
1.4 +2 -2 logging-log4j/tests/witness/xmlLayout.mdc.1
Index: xmlLayout.mdc.1
===================================================================
RCS file: /home/cvs/logging-log4j/tests/witness/xmlLayout.mdc.1,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- xmlLayout.mdc.1 28 Apr 2004 17:54:02 -0000 1.3
+++ xmlLayout.mdc.1 9 May 2004 19:15:03 -0000 1.4
@@ -1,8 +1,8 @@
<log4j:event logger="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX"
sequenceNumber="XXX" level="DEBUG" thread="main">
<log4j:message><![CDATA[Hello]]></log4j:message>
-<log4j:MDC>
+<log4j:properties>
<log4j:data name="key1" value="val1"/>
<log4j:data name="key2" value="val2"/>
-</log4j:MDC>
+</log4j:properties>
</log4j:event>
1.2 +1 -1 logging-log4j/tests/witness/patternLayout.mdc.1
Index: patternLayout.mdc.1
===================================================================
RCS file: /home/cvs/logging-log4j/tests/witness/patternLayout.mdc.1,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- patternLayout.mdc.1 26 Mar 2003 06:26:48 -0000 1.1
+++ patternLayout.mdc.1 9 May 2004 19:15:03 -0000 1.2
@@ -1 +1 @@
-DEBUG - Hello World {{key2,va12}{key1,va11}}
\ No newline at end of file
+DEBUG - Hello World {{key1,va11}{key2,va12}}
\ No newline at end of file
1.2 +2 -2 logging-log4j/tests/witness/xmlLayout.mdc.2
Index: xmlLayout.mdc.2
===================================================================
RCS file: /home/cvs/logging-log4j/tests/witness/xmlLayout.mdc.2,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xmlLayout.mdc.2 26 Mar 2003 06:26:48 -0000 1.1
+++ xmlLayout.mdc.2 9 May 2004 19:15:03 -0000 1.2
@@ -1,8 +1,8 @@
<log4j:event logger="org.apache.log4j.xml.XMLLayoutTestCase" timestamp="XXX"
level="DEBUG" thread="main">
<log4j:message><![CDATA[Hello]]></log4j:message>
-<log4j:MDC>
+<log4j:properties>
<log4j:data name="<![CDATA[<blahKey value="blah"/>]]>"
value="<![CDATA[blahValue]]>"/>
<log4j:data name="<![CDATA[blahAttribute]]>" value="<![CDATA[<blah
value="blah">]]>"/>
-</log4j:MDC>
+</log4j:properties>
</log4j:event>
1.2 +1 -1 logging-log4j/tests/witness/patternLayout.mdc.2
Index: patternLayout.mdc.2
===================================================================
RCS file: /home/cvs/logging-log4j/tests/witness/patternLayout.mdc.2,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- patternLayout.mdc.2 18 Sep 2003 21:26:55 -0000 1.1
+++ patternLayout.mdc.2 9 May 2004 19:15:03 -0000 1.2
@@ -4,7 +4,7 @@
empty mdc, key2 in pattern :
empty mdc, key3 in pattern :
empty mdc, key1, key2, and key3 in pattern : ,,
-filled mdc, no key specified in pattern : {{key2,value2}{key1,value1}}
+filled mdc, no key specified in pattern : {{key1,value1}{key2,value2}}
filled mdc, key1 in pattern : value1
filled mdc, key2 in pattern : value2
filled mdc, key3 in pattern :
1.53 +74 -57 logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- LoggingEvent.java 9 May 2004 18:37:56 -0000 1.52
+++ LoggingEvent.java 9 May 2004 19:15:03 -0000 1.53
@@ -19,10 +19,10 @@
import java.io.ObjectOutputStream;
import java.lang.reflect.Method;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
+import java.util.TreeMap;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@@ -128,8 +128,8 @@
private String ndc;
/**
- * <p>The properties map is specific for this event.</p>
- *
+ * <p>The properties map is specific for this event.</p>
+ *
* <p>When serialized, it contains a copy of MDC properties as well
* as LoggerRepository properties.
* </p>
@@ -316,7 +316,7 @@
* the higher 32 bits of timeStamp;
*/
public int hashCode() {
- return (int)( (timeStamp >> 32) ^ (sequenceNumber & 0xFFFFFFFF) );
+ return (int)((timeStamp >> 32) ^ (sequenceNumber & 0xFFFFFFFF));
}
@@ -343,21 +343,22 @@
/**
- * Return the level of this event.
+ * Return the level of this event.
*/
public Level getLevel() {
return (Level)level;
}
+
/**
* Set the level of this event. The level can be set at most once.
- *
+ *
* @param level The level to set.
* @throws IllegalStateException if the level has been already set.
* @since 1.3
*/
public void setLevel(Level level) {
- if(this.level != null) {
+ if (this.level != null) {
throw new IllegalStateException("The level has been already set for this
event.");
}
this.level = level;
@@ -376,32 +377,31 @@
/**
- * Set the logger of this event. Calling this method also sets the
<code>loggerName</code>
+ * Set the logger of this event. Calling this method also sets the
<code>loggerName</code>
* for the event. The logger can be set at most once.
- *
+ *
* Moreover, if the loggerName has been already set, this method will throw
* an [EMAIL PROTECTED] IllegalStateException}.
- *
+ *
* @throws IllegalStateException
*/
public void setLogger(Logger logger) {
- if(this.logger != null) {
- throw new IllegalStateException("logger has been already set to ["
- + this.logger.getName() + "].");
- }
-
- if(this.loggerName != null) {
- throw new IllegalStateException("loggerName has been already set to ["
- + this.loggerName + "], logger "+logger.getName()+"] is invalid");
+ if (this.logger != null) {
+ throw new IllegalStateException("logger has been already set to [" +
this.logger.getName() + "].");
}
-
+
+ if (this.loggerName != null) {
+ throw new IllegalStateException("loggerName has been already set to [" +
this.loggerName + "], logger "
+ + logger.getName() + "] is invalid");
+ }
+
this.logger = logger;
this.loggerName = logger.getName();
}
/**
- * Return the name of the logger.
+ * Return the name of the logger.
*/
public String getLoggerName() {
return loggerName;
@@ -410,15 +410,15 @@
/**
* Set the loggerName for this event. The loggerName can be set at most once.
- *
+ *
* @param loggerName The loggerName to set.
* @throws IllegalStateException if loggerName is already set
* @since 1.3
*/
- public void setLoggerName(String loggerName) throws IllegalStateException {
+ public void setLoggerName(String loggerName)
+ throws IllegalStateException {
if (this.loggerName != null) {
- throw new IllegalStateException("loggerName has been already set to ["
- + this.loggerName + "].");
+ throw new IllegalStateException("loggerName has been already set to [" +
this.loggerName + "].");
} else {
this.loggerName = loggerName;
}
@@ -445,17 +445,19 @@
}
}
+
/**
- * Set the message for this event. The
+ * Set the message for this event. The
* @param message The message to set.
* @since 1.3
*/
public void setMessage(Object message) {
- if(this.message != null) {
+ if (this.message != null) {
throw new IllegalStateException("The message for this event has been set
alredy.");
}
+
// After serialisation, message will be null and renderedMessage will be
non-null.
- if(this.renderedMessage != null) {
+ if (this.renderedMessage != null) {
throw new IllegalStateException("The message cannot be set if the
renderedMessage has been set.");
}
this.message = message;
@@ -557,10 +559,13 @@
*/
public void createProperties() {
if (properties == null) {
- properties = new HashMap();
- properties.putAll(MDC.getContext());
- if(logger != null) {
- properties.putAll(logger.getLoggerRepository().getProperties());
+ properties = new TreeMap();
+ Map mdcMap = MDC.getContext();
+ if(mdcMap != null) {
+ properties.putAll(mdcMap);
+ }
+ if (logger != null) {
+ properties.putAll(logger.getLoggerRepository().getProperties());
}
}
}
@@ -568,7 +573,7 @@
/**
* Return a property for this event. The return value can be null.
- *
+ *
* <p>The property is searched first in the properties map specific for this
* event, then in the MDC, then in the logger repository containing the logger
* of this event.
@@ -576,21 +581,26 @@
*/
public String getProperty(String key) {
String value = null;
+
if (properties != null) {
- value = (String) properties.get(key);
- if(value != null) {
- return value;
- }
- } else { // properties is null
- value = MDC.get(key);
- if(value != null) {
+ value = (String)properties.get(key);
+
+ if (value != null) {
return value;
}
-
- if(logger != null) {
- value = logger.getLoggerRepository().getProperty(key);
- }
}
+
+ // if the key was not found in this even't properties, try the MDC
+ value = MDC.get(key);
+ if (value != null) {
+ return value;
+ }
+
+ // if still not found try, the properties in the logger repository
+ if (logger != null) {
+ value = logger.getLoggerRepository().getProperty(key);
+ }
+
return value;
}
@@ -638,19 +648,22 @@
return renderedMessage;
}
+
/**
- *
+ *
* @param renderedMessage The renderedMessage to set.
* @throws IllegalStateException if renderedMessage has been already set.
* @since 1.3
*/
- public void setRenderedMessage(String renderedMessage) throws
IllegalStateException {
- if(this.renderedMessage != null) {
- throw new IllegalStateException("renderedMessage has been already set.");
+ public void setRenderedMessage(String renderedMessage)
+ throws IllegalStateException {
+ if (this.renderedMessage != null) {
+ throw new IllegalStateException("renderedMessage has been already set.");
}
this.renderedMessage = renderedMessage;
}
+
/**
* Returns the time when the application started, in milliseconds elapsed
* since 01.01.1970.
@@ -686,18 +699,20 @@
return threadName;
}
- /**
- * @param threadName The threadName to set.
- * @throws IllegalStateException If threadName has been already set.
- */
- public void setThreadName(String threadName) throws IllegalStateException {
- if(this.threadName != null) {
+
+ /**
+ * @param threadName The threadName to set.
+ * @throws IllegalStateException If threadName has been already set.
+ */
+ public void setThreadName(String threadName)
+ throws IllegalStateException {
+ if (this.threadName != null) {
throw new IllegalStateException("threadName has been already set");
}
this.threadName = threadName;
- }
-
-
+ }
+
+
/**
* Returns the throwable information contained within this event. May be
* <code>null</code> if there is no such information.
@@ -772,8 +787,9 @@
}
}
+
/**
- * @return Returns the properties specific for this event. The returned
+ * @return Returns the properties specific for this event. The returned
* value can be null.
* @since 1.3
*/
@@ -788,6 +804,7 @@
public void setProperties(Hashtable properties) {
this.properties = properties;
}
+
/**
* Set a string property using a key and a string value. since 1.3
1.28 +2 -2 logging-log4j/src/java/org/apache/log4j/xml/XMLLayout.java
Index: XMLLayout.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/xml/XMLLayout.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- XMLLayout.java 9 May 2004 18:37:57 -0000 1.27
+++ XMLLayout.java 9 May 2004 19:15:03 -0000 1.28
@@ -183,13 +183,13 @@
Set propertySet = event.getPropertyKeySet();
if ((propertySet != null) && (propertySet.size() > 0)) {
- output.write("<log4j:properties>");
+ output.write("<log4j:properties>\r\n");
Iterator propIter = propertySet.iterator();
while (propIter.hasNext()) {
String propName = propIter.next().toString();
- output.write("<log4j:data name=\"" + propName);
+ output.write(" <log4j:data name=\"" + propName);
String propValue = event.getProperty(propName).toString();
output.write("\" value=\"" + propValue);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]