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 2001/01/17 14:02:28 UTC
cvs commit: jakarta-log4j/org/apache/log4j/test AsyncAppenderTest.java asyncTest.xml Makefile
ceki 01/01/17 05:02:27
Modified: org/apache/log4j AsyncAppender.java
org/apache/log4j/helpers AppenderAttachableImpl.java
OptionConverter.java
org/apache/log4j/performance Logging.java
org/apache/log4j/test Makefile
Added: org/apache/log4j/test AsyncAppenderTest.java asyncTest.xml
Log:
Cleaned up AsyncAppender. Miscallenous corrections in documentaiton.
Revision Changes Path
1.6 +16 -9 jakarta-log4j/org/apache/log4j/AsyncAppender.java
Index: AsyncAppender.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/AsyncAppender.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AsyncAppender.java 2001/01/17 09:57:32 1.5
+++ AsyncAppender.java 2001/01/17 13:02:23 1.6
@@ -31,8 +31,11 @@
for the impact of using this appender.
<p><b>Important note:</b> The <code>AsyncAppender</code> can only
- be script configured using the {@link org.apache.log4j.xml.DOMConfigurator}.
-
+ be script configured using the {@link
+ org.apache.log4j.xml.DOMConfigurator}. Refer to the
+ <code>org/apache/log4j/performace/xml</code> directory for
+ examples.
+
@author Ceki Gülcü
@since version 0.9.1 */
public class AsyncAppender extends AppenderSkeleton
@@ -215,10 +218,15 @@
}
- synchronized
void close() {
- interrupted = true;
- bf.notify();
+ synchronized(bf) {
+ interrupted = true;
+ // We have a waiting dispacther if and only if bf.length is
+ // zero. In that case, we need to give its death kiss.
+ if(bf.length() == 0) {
+ bf.notify();
+ }
+ }
}
@@ -243,8 +251,7 @@
while(true) {
synchronized(bf) {
if(bf.length() == 0) {
- // exit loop if we are interrupted but only if the the
- // buffer is empty.
+ // Exit loop if interrupted but only if the the buffer is empty.
if(interrupted) {
//cat.info("Exiting.");
return;
@@ -253,7 +260,7 @@
//cat.debug("Waiting for new event to dispatch.");
bf.wait();
} catch(InterruptedException e) {
- //cat.info("Dispatcher interrupted.");
+ LogLog.error("The dispathcer should not be interrupted.");
break;
}
}
@@ -265,7 +272,7 @@
}
} // synchronized
- if(aai != null)
+ if(aai != null && event != null)
aai.appendLoopOnAppenders(event);
} // while
}
1.4 +3 -2 jakarta-log4j/org/apache/log4j/helpers/AppenderAttachableImpl.java
Index: AppenderAttachableImpl.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/helpers/AppenderAttachableImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AppenderAttachableImpl.java 2000/12/26 21:42:47 1.3
+++ AppenderAttachableImpl.java 2001/01/17 13:02:24 1.4
@@ -27,8 +27,9 @@
protected Vector appenderList;
/**
- Attach an appender.
- */
+ Attach an appender. If the appender is already in the list in
+ won't be added again.
+ */
public
void addAppender(Appender newAppender) {
// Null values for newAppender parameter are strictly forbidden.
1.10 +3 -3 jakarta-log4j/org/apache/log4j/helpers/OptionConverter.java
Index: OptionConverter.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/helpers/OptionConverter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- OptionConverter.java 2001/01/17 09:57:33 1.9
+++ OptionConverter.java 2001/01/17 13:02:24 1.10
@@ -235,7 +235,7 @@
<p>The variable substitution delimeters are <b>${</b> and <b>}</b>.
- <p>For example, if the system properties contains "key=value", then
+ <p>For example, if the System properties contains "key=value", then
the call
<pre>
String s = OptionConverter.substituteVars("Value of key is ${key}.");
@@ -243,7 +243,7 @@
will set the variable <code>s</code> to "Value of key is value.".
- If no value could be found for the specified key, then the
+ <p>If no value could be found for the specified key, then the
<code>props</code> parameter is searched, if the value could not
be found there, then substitution defaults to the empty string.
@@ -295,7 +295,7 @@
j += DELIM_START_LEN;
String key = val.substring(j, k);
// first try in System properties
- String replacement = System.getProperty(key);
+ String replacement = getSystemProperty(key, null);
// then try props parameter
if(replacement == null && props != null) {
replacement = props.getProperty(key);
1.5 +3 -3 jakarta-log4j/org/apache/log4j/performance/Logging.java
Index: Logging.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/performance/Logging.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Logging.java 2001/01/17 09:28:57 1.4
+++ Logging.java 2001/01/17 13:02:25 1.5
@@ -197,15 +197,15 @@
void Usage(String msg) {
System.err.println(msg);
System.err.println(
- "Usage: java org.apache.log4j.test.Logging confFile runLength delay burstLen\n"+
- " confFile is a configuration file and\n"+
+ "Usage: java "+Logging.class.getName()+" confFile runLength [delay] [burstLen]\n"+
+ " confFile is an XML configuration file and\n"+
" runLength (integer) is the length of test loop.\n"+
" delay is the time in millisecs to wait every bustLen log requests.");
System.exit(1);
}
/**
- <b>Usage:</b> <code>java org.apache.log4j.test.Logging confFile runLength [delay] [burstLen]</code>
+ <b>Usage:</b> <code>java org.apache.log4j.performance.Logging confFile runLength [delay] [burstLen]</code>
<p><code>confFile</code> is an XML configuration file and
<code>runLength</code> (integer) is the length of test loop,
1.4 +1 -0 jakarta-log4j/org/apache/log4j/test/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/test/Makefile,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile 2000/12/14 21:08:13 1.3
+++ Makefile 2001/01/17 13:02:27 1.4
@@ -12,6 +12,7 @@
PatternTest.java\
ROFile.java\
L7D.java\
+ AsyncAppenderTest.java\
Finalize.java\
DefaultInit.java\
CategoryWrapper.java\
1.1 jakarta-log4j/org/apache/log4j/test/AsyncAppenderTest.java
Index: AsyncAppenderTest.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.APL file.
*/
package org.apache.log4j.test;
import org.apache.log4j.Category;
import org.apache.log4j.xml.DOMConfigurator;
/**
Test the coordination of the AsyncAppender with its Dispatcher.
@author Ceki Gülcü
*/
public class AsyncAppenderTest {
static Category cat = Category.getInstance(AsyncAppenderTest.class);
static int delayBeforeClose;
public
static
void main(String argv[]) {
if(argv.length == 2)
init(argv[0], argv[1]);
else
usage("Wrong number of arguments.");
test();
}
static
void usage(String msg) {
System.err.println(msg);
System.err.println( "Usage: java "+ Shallow.class.getName() +
"configFile");
System.exit(1);
}
static
void init(String configFile, String delayBeforeCloseStr) {
DOMConfigurator.configure(configFile);
try {
delayBeforeClose = Integer.parseInt(delayBeforeCloseStr);
} catch(java.lang.NumberFormatException e) {
e.printStackTrace();
usage("Could not convert ["+delayBeforeCloseStr+"] to Integer.");
}
}
static
void test() {
Category root = Category.getRoot();
for(int i = 0; i < 100; i++) {
root.debug("Message " + i);
}
try{Thread.currentThread().sleep(delayBeforeClose);}catch(Exception e){}
Category.shutdown();
}
}
1.1 jakarta-log4j/org/apache/log4j/test/asyncTest.xml
Index: asyncTest.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration SYSTEM "log4j.dtd">
<configuration>
<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
<appender-ref ref="TEMP" />
</appender>
<appender name="TEMP" class="org.apache.log4j.FileAppender">
<param name="File" value="System.out"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%p - %m%n"/>
</layout>
</appender>
<root>
<priority value ="debug" />
<appender-ref ref="ASYNC" />
</root>
</configuration>