You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2002/05/09 19:44:55 UTC
cvs commit: jakarta-log4j/tests/src/java/org/apache/log4j/helpers OptionConverterTestCase.java
ceki 02/05/09 10:44:54
Modified: docs HISTORY
src/java/org/apache/log4j AppenderSkeleton.java
AsyncAppender.java Category.java
src/java/org/apache/log4j/spi LoggingEvent.java
tests build.xml
tests/src/java/org/apache/log4j/helpers
OptionConverterTestCase.java
Added: tests/src/java/org/apache/log4j AsyncAppenderTestCase.java
VectorAppender.java
Log:
Corrected a bug in AppenderSkeleton.doAppend which did not prevent from
appending to a closed a appender.
New test case AsyncAppenderTestCase. This test case uses VectorAppender
which is simpler to use then writing a regression test against a witness.
Revision Changes Path
1.95 +4 -0 jakarta-log4j/docs/HISTORY
Index: HISTORY
===================================================================
RCS file: /home/cvs/jakarta-log4j/docs/HISTORY,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- HISTORY 9 May 2002 15:43:43 -0000 1.94
+++ HISTORY 9 May 2002 17:44:54 -0000 1.95
@@ -9,6 +9,10 @@
- Release of version 1.2
+
+ - AsyncAppender throws NullPointerException problem. The bug was actually in
+ AppenderSkeleton. See bug #5444 for more details. [*]
+
- Added support for recursive variable substiuton as requested by
Eric Chastan. [*]
1.19 +2 -1 jakarta-log4j/src/java/org/apache/log4j/AppenderSkeleton.java
Index: AppenderSkeleton.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/AppenderSkeleton.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- AppenderSkeleton.java 5 Sep 2001 06:45:28 -0000 1.18
+++ AppenderSkeleton.java 9 May 2002 17:44:54 -0000 1.19
@@ -201,8 +201,9 @@
void doAppend(LoggingEvent event) {
if(closed) {
LogLog.error("Attempted to append to closed appender named ["+name+"].");
+ return;
}
-
+
if(!isAsSevereAsThreshold(event.level)) {
return;
}
1.30 +3 -28 jakarta-log4j/src/java/org/apache/log4j/AsyncAppender.java
Index: AsyncAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/AsyncAppender.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- AsyncAppender.java 9 May 2002 15:43:43 -0000 1.29
+++ AsyncAppender.java 9 May 2002 17:44:54 -0000 1.30
@@ -44,33 +44,6 @@
public class AsyncAppender extends AppenderSkeleton
implements AppenderAttachable {
- /**
- A string constant used in naming the option for setting the
- location information flag. Current value of this string
- constant is <b>LocationInfo</b>.
-
- <p>Note that all option keys are case sensitive.
-
- @deprecated Options are now handled using the JavaBeans paradigm.
- This constant is not longer needed and will be removed in the
- <em>near</em> term.
- */
- public static final String LOCATION_INFO_OPTION = "LocationInfo";
-
-
- /**
- A string constant used in naming the option for setting the size of the
- internal buffer where logging events are stored until they are written.
- Current value of this string constant is <b>BufferSize</b>.
-
- <p>Note that all option keys are case sensitive.
-
- @deprecated Options are now handled using the JavaBeans paradigm.
- This constant is not longer needed and will be removed in the
- <em>near</em> term.
- */
- public static final String BUFFER_SIZE_OPTION = "BufferSize";
-
/** The default buffer size is set to 128 events. */
public static final int DEFAULT_BUFFER_SIZE = 128;
@@ -144,8 +117,10 @@
public
void close() {
synchronized(this) {
- if(closed) // avoid multiple close, otherwise one gets NullPointerException
+ // avoid multiple close, otherwise one gets NullPointerException
+ if(closed) {
return;
+ }
closed = true;
}
1.67 +0 -9 jakarta-log4j/src/java/org/apache/log4j/Category.java
Index: Category.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Category.java,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- Category.java 24 Apr 2002 15:03:44 -0000 1.66
+++ Category.java 9 May 2002 17:44:54 -0000 1.67
@@ -263,15 +263,6 @@
forcedLog(FQCN, Level.DEBUG, message, t);
}
- //public
- //void dump() {
- // System.out.println("Category " + name + " dump -----");
- // for(Category c = this; c != null; c=c.parent)
- // System.out.println("("+c.name+", "+c.level+") ->");
- // System.out.println("---------------------------");
- //
- //}
-
/**
Log a message object with the {@link Level#ERROR ERROR} Level.
1.31 +4 -1 jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- LoggingEvent.java 9 May 2002 15:43:44 -0000 1.30
+++ LoggingEvent.java 9 May 2002 17:44:54 -0000 1.31
@@ -230,7 +230,10 @@
ndcLookupRequired = false;
// the clone call is required for asynchronous logging.
// See also bug #5932.
- mdcCopy = (Hashtable) MDC.getContext().clone();
+ Hashtable t = (Hashtable) MDC.getContext();
+ if(t != null) {
+ mdcCopy = (Hashtable) t.clone();
+ }
}
}
1.14 +12 -9 jakarta-log4j/tests/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-log4j/tests/build.xml,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- build.xml 25 Apr 2002 21:17:36 -0000 1.13
+++ build.xml 9 May 2002 17:44:54 -0000 1.14
@@ -87,7 +87,7 @@
<!-- ================================================================= -->
<!-- Run all tests -->
<!-- ================================================================= -->
- <target name="runAll" depends="regression, unit, longUnit"/>
+ <target name="runAll" depends="regression, longUnit"/>
<!-- ================================================================= -->
<!-- Tests multiple parts of log4j. These tests are much more fragile -->
@@ -97,14 +97,9 @@
<target name="regression" depends="Minimum, Logger, DOM, CustomLevel,
CustomLogger, PatternLayout,
HierarchyThreshold, SocketServer,
- XMLLayout"/>
-
- <!-- ================================================================= -->
- <!-- Unit tests test small parts of log4j for logical programming -->
- <!-- errors. This is different than regression tests which check -->
- <!-- larger parts of log4j. -->
- <!-- ================================================================= -->
- <target name="unit" depends="OptionConverter, BoundedFIFO, CyclicBuffer, OR"/>
+ XMLLayout, AsyncAppender,
+ OptionConverter, BoundedFIFO,
+ CyclicBuffer, OR"/>
<!-- ================================================================= -->
<!-- Longer unit tests -->
@@ -195,6 +190,14 @@
<classpath refid="tests.classpath"/>
<formatter type="plain" usefile="false" />
<test name="org.apache.log4j.xml.XMLLayoutTestCase" />
+ </junit>
+ </target>
+
+ <target name="AsyncAppender" depends="build">
+ <junit printsummary="yes" fork="yes" haltonfailure="yes">
+ <classpath refid="tests.classpath"/>
+ <formatter type="plain" usefile="false" />
+ <test name="org.apache.log4j.AsyncAppenderTestCase" />
</junit>
</target>
1.1 jakarta-log4j/tests/src/java/org/apache/log4j/AsyncAppenderTestCase.java
Index: AsyncAppenderTestCase.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
package org.apache.log4j;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Test;
import java.util.Vector;
import org.apache.log4j.*;
import org.apache.log4j.performance.NullAppender;
/**
A superficial but general test of log4j.
*/
public class AsyncAppenderTestCase extends TestCase {
public AsyncAppenderTestCase(String name) {
super(name);
}
public void setUp() {
}
public void tearDown() {
}
public void closeTest() throws Exception {
Logger root = Logger.getRootLogger();
Layout layout = new SimpleLayout();
VectorAppender vectorAppender = new VectorAppender();
AsyncAppender asyncAppender = new AsyncAppender();
asyncAppender.addAppender(vectorAppender);
root.addAppender(asyncAppender);
root.debug("m1");
asyncAppender.close();
root.debug("m2");
Vector v = vectorAppender.getVector();
assertEquals(v.size(), 1);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new AsyncAppenderTestCase("closeTest"));
return suite;
}
}
1.1 jakarta-log4j/tests/src/java/org/apache/log4j/VectorAppender.java
Index: VectorAppender.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software
* License version 1.1, a copy of which has been included with this
* distribution in the LICENSE.txt file. */
package org.apache.log4j;
import java.util.Vector;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.helpers.DateLayout;
import org.apache.log4j.helpers.Transform;
import org.apache.log4j.helpers.LogLog;
/**
An appender that appends logging events to a vector.
@author Ceki Gülcü
*/
public class VectorAppender extends AppenderSkeleton {
public Vector vector;
public
VectorAppender() {
vector = new Vector();
}
/**
Does nothing.
*/
public
void activateOptions() {
}
/**
This method is called by the {@link AppenderSkeleton#doAppend}
method.
*/
public
void append(LoggingEvent event) {
System.out.println("---Vector appender called with message ["+event.getRenderedMessage()+"].");
vector.addElement(event);
}
public
Vector getVector() {
return vector;
}
public
synchronized
void close() {
if(this.closed)
return;
this.closed = true;
}
public
boolean requiresLayout() {
return false;
}
}
1.3 +0 -1 jakarta-log4j/tests/src/java/org/apache/log4j/helpers/OptionConverterTestCase.java
Index: OptionConverterTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/helpers/OptionConverterTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- OptionConverterTestCase.java 9 May 2002 15:43:44 -0000 1.2
+++ OptionConverterTestCase.java 9 May 2002 17:44:54 -0000 1.3
@@ -91,7 +91,6 @@
public
void varSubstTest5() {
- System.out.println("-----------------------------------------");
Properties props = new Properties();
props.put("p1", "x1");
props.put("p2", "${p1}");
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>