ceki 01/05/20 06:21:59
Modified: src/java/org/apache/log4j PatternLayout.java
PropertyConfigurator.java
src/java/org/apache/log4j/test Makefile pattern
src/java/org/apache/log4j/xml DOMConfigurator.java
Added: src/java/org/apache/log4j/test CustomCategoryTest.java
customCategory
src/java/org/apache/log4j/test/witness customCat.1
Log:
Added support for custom priorities in ProppertyConfigurator.
Revision Changes Path
1.11 +2 -2 jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java
Index: PatternLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- PatternLayout.java 2001/05/20 11:08:06 1.10
+++ PatternLayout.java 2001/05/20 13:21:56 1.11
@@ -71,12 +71,12 @@
the end of a conversion specifier when it reads a conversion
character. In the example above the conversion specifier
<b>%-5p</b> means the priority of the logging event should be left
- justified to a with of five characters.
+ justified to a width of five characters.
The recognized conversion characters are
<p>
- <table border=1 CELLPADDING=8>
+ <table border="1" CELLPADDING="8">
<th>Conversion Character</th>
<th>Effect</th>
1.21 +36 -24
jakarta-log4j/src/java/org/apache/log4j/PropertyConfigurator.java
Index: PropertyConfigurator.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/PropertyConfigurator.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- PropertyConfigurator.java 2001/05/20 11:15:24 1.20
+++ PropertyConfigurator.java 2001/05/20 13:21:57 1.21
@@ -41,7 +41,7 @@
<p>It is sometimes useful to see how log4j is reading configuration
files. You can enable log4j internal logging by defining the
- <b>log4j.configDebug</b> variable.
+ <b>log4j.debug</b> variable.
<P>As of log4j version 0.8.5, at the initialization of the Category
class, the file <b>log4j.properties</b> will be searched from the
@@ -51,10 +51,10 @@
<p>The <code>PropertyConfigurator</code> does not handle the
advanced configuration features supported by the {@link
- org.apache.log4j.xml.DOMConfigurator DOMConfigurator} such as support for
- sub-classing of the Priority class, {@link org.apache.log4j.spi.Filter
- Filters}, custom {@link org.apache.log4j.spi.ErrorHandler ErrorHandlers},
- nested appenders such as the {@link org.apache.log4j.AsyncAppender
+ org.apache.log4j.xml.DOMConfigurator DOMConfigurator} such as
+ support for @link org.apache.log4j.spi.Filter Filters}, custom
+ {@link org.apache.log4j.spi.ErrorHandler ErrorHandlers}, nested
+ appenders such as the {@link org.apache.log4j.AsyncAppender
AsyncAppender}, etc.
<p><em>All option values admit variable substitution.</em> For
@@ -97,14 +97,15 @@
static final private String INTERNAL_ROOT_NAME = "root";
/**
- Read configuration from a file. The existing configuration is not
- cleared nor reset. If you require a different call, behavior,
+ Read configuration from a file. <b>The existing configuration is
+ not cleared nor reset.</b> If you require a different behavior,
then call {@link BasicConfigurator#resetConfiguration
resetConfiguration} method before calling
<code>doConfigure</code>.
<p>The configuration file consists of statements in the format
- <code>key=value</code>.
+ <code>key=value</code>. The syntax of different configuration
+ elements are discussed below.
<h3>Appender configuration</h3>
@@ -133,18 +134,28 @@
<p>The syntax for configuring the root category is:
<pre>
- log4j.rootCategory=[FATAL|ERROR|WARN|INFO|DEBUG], appenderName, appenderName,
...
+ log4j.rootCategory=[priority], appenderName, appenderName, ...
</pre>
- <p>This syntax means that one of the strings values ERROR, WARN,
- INFO or DEBUG can be supplied followed by appender names separated
- by commas.
-
- <p>If one of the optional priority values ERROR, WARN, INFO or
- DEBUG is given, the root priority is set to the corresponding
- priority. If no priority value is specified, then the root
- priority remains untouched.
+ <p>This syntax means that an optional <em>priority value</em> can
+ be supplied followed by appender names separated by commas.
+
+
+
+ <p>The priority value can consist of the string values FATAL,
+ ERROR, WARN, INFO or DEBUG. However, you can specify a custom
+ priority value in the form <code>priority#classname</code>. In
+ that case, the specified class' toPriority method is called to
+ process the specified priority string; if no '#' character is
+ present, then the default {@link Priority} class is used to
+ process the priority value.
+
+ <p>If one of the optional priority value is specified, then the
+ root priority is set to the corresponding priority. If no
+ priority value is specified, then the root priority remains
+ untouched.
+
<p>The root category can be assigned multiple appenders.
<p>Each <i>appenderName</i> (separated by commas) will be added to
@@ -430,9 +441,9 @@
}
- // -------------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
// Internal stuff
- // -------------------------------------------------------------------------------
+ // --------------------------------------------------------------------------
void configureCategoryFactory(Properties props) {
String factoryClassName = OptionConverter.findAndSubst(CATEGORY_FACTORY_KEY,
@@ -533,8 +544,7 @@
LogLog.debug("Parsing for [" +catName +"] with value=[" + value+"].");
// We must skip over ',' but not white space
StringTokenizer st = new StringTokenizer(value, ",");
-
-
+
// If value is not in the form ", appender.." or "", then we should set
// the priority of the category.
@@ -551,10 +561,12 @@
// null. We also check that the user has not specified inherited for the
// root category.
if(priorityStr.equalsIgnoreCase(BasicConfigurator.INHERITED) &&
- !catName.equals(INTERNAL_ROOT_NAME))
+ !catName.equals(INTERNAL_ROOT_NAME)) {
cat.setPriority(null);
- else
- cat.setPriority(Priority.toPriority(priorityStr));
+ } else {
+ cat.setPriority(OptionConverter.toPriority(priorityStr,
+ Priority.DEBUG));
+ }
LogLog.debug("Category " + catName + " set to " + cat.getPriority());
}
1.12 +1 -0 jakarta-log4j/src/java/org/apache/log4j/test/Makefile
Index: Makefile
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/Makefile,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Makefile 2001/04/26 08:16:26 1.11
+++ Makefile 2001/05/20 13:21:57 1.12
@@ -25,6 +25,7 @@
UnitTestOptionConverter.java\
SocketAppenderTest.java\
PrintProperties.java\
+ CustomCategoryTest.java\
ifdef $(ISJDK1)
1.6 +1 -0 jakarta-log4j/src/java/org/apache/log4j/test/pattern
Index: pattern
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/test/pattern,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- pattern 2001/05/09 19:39:54 1.5
+++ pattern 2001/05/20 13:21:57 1.6
@@ -194,3 +194,4 @@
# lecho "log4j.appender.testAppender.layout=org.apache.log4j.HTMLLayout"
# testPattern HTML
#fi
+
1.1
jakarta-log4j/src/java/org/apache/log4j/test/CustomCategoryTest.java
Index: CustomCategoryTest.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.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;
import org.apache.log4j.Category;
import org.apache.log4j.NDC;
import org.apache.log4j.Priority;
import org.apache.log4j.xml.examples.XPriority;
import org.apache.log4j.xml.examples.XCategory;
import java.io.IOException;
import java.util.Enumeration;
/**
This class is used to test support for custom priorities.
@author Ceki Gülcü
*/
public class CustomCategoryTest {
static XCategory cat = (XCategory)
XCategory.getInstance(CustomCategoryTest.class);
public
static
void main(String argv[]) {
if(argv.length == 1)
init(argv[0]);
else
usage("Wrong number of arguments.");
test();
}
static
void usage(String msg) {
System.err.println(msg);
System.err.println( "Usage: java "+ CustomCategoryTest.class.getName()
+" configFile");
System.exit(1);
}
static
void init(String configFile) {
if(configFile.endsWith(".xml"))
DOMConfigurator.configure(configFile);
else
PropertyConfigurator.configure(configFile);
}
static
void test() {
int i = -1;
cat.trace("Message " + ++i);
cat.debug("Message " + ++i);
cat.info("Message " + ++i);
cat.warn("Message " + ++i);
cat.error("Message " + ++i);
cat.lethal("Message " + ++i);
// It is always a good idea to call this method when exiting an
// application.
Category.shutdown();
}
}
1.1 jakarta-log4j/src/java/org/apache/log4j/test/customCategory
Index: customCategory
===================================================================
#!/bin/bash
# A regression test to check support custom priorities
# Read the .functions file
. .functions
# If set, allows to skip tests
declare -i start=$1
echo "start=$start TEMP=$TEMP OUTPUT=$OUTPUT"
function testCustomCat {
layout=$1
echo -n "Custom Priority test $TEST - "
java org.apache.log4j.test.CustomCategoryTest $LCF
check witness/customCat.$TEST $OUTPUT; echo "OK."
}
setPERL
declare -i TEST
TEST=1
if [ $TEST -ge $start ]; then
echo "LOG4J=org.apache.log4j" > $LCF
lecho "log4j.rootCategory=TRACE#\${LOG4J}.xml.examples.XPriority, testAppender"
lecho "log4j.categoryFactory=\${LOG4J}.examples.MyCategoryFactory"
lecho "log4j.appender.testAppender=\${LOG4J}.FileAppender"
lecho "log4j.appender.testAppender=\${LOG4J}.FileAppender"
lecho "log4j.appender.testAppender.File=$TEMP"
lecho "log4j.appender.testAppender.Append=false"
lecho "log4j.appender.testAppender.layout=\${LOG4J}.PatternLayout "
lecho "log4j.appender.testAppender.layout.ConversionPattern=%-5p - %m%n"
testCustomCat
fi
1.1 jakarta-log4j/src/java/org/apache/log4j/test/witness/customCat.1
Index: customCat.1
===================================================================
TRACE - Message 0
DEBUG - Message 1
INFO - Message 2
WARN - Message 3
ERROR - Message 4
LETHAL - Message 5
1.21 +10 -3 jakarta-log4j/src/java/org/apache/log4j/xml/DOMConfigurator.java
Index: DOMConfigurator.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/DOMConfigurator.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DOMConfigurator.java 2001/05/18 20:45:17 1.20
+++ DOMConfigurator.java 2001/05/20 13:21:58 1.21
@@ -591,14 +591,21 @@
}
-
/**
- This is the static version of {@link #doConfigure(String, Hierarchy)}.x
- */
+ A static version of {@link #doConfigure(String, Hierarchy)}. */
static
public
void configure(String filename) throws FactoryConfigurationError {
new DOMConfigurator().doConfigure(filename, Category.getDefaultHierarchy());
+ }
+
+ /**
+ A static version of {@link #doConfigure(URL, Hierarchy)}.
+ */
+ static
+ public
+ void configure(URL url) throws FactoryConfigurationError {
+ new DOMConfigurator().doConfigure(url, Category.getDefaultHierarchy());
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]