public class DOMConfigurator extends Object implements Configurator
The DTD is specified in log4j.dtd.
Sometimes it is useful to see how log4j is reading configuration
files. You can enable log4j internal logging by defining the
log4j.debug variable on the java command
line. Alternatively, set the debug
attribute in the
log4j:configuration
element. As in
<log4j:configuration debug="true" xmlns:log4j="http://jakarta.apache.org/log4j/"> ... </log4j:configuration>
There are sample XML files included in the package.
Modifier and Type | Class and Description |
---|---|
private static interface |
DOMConfigurator.ParseAction |
Modifier and Type | Field and Description |
---|---|
(package private) static String |
ADDITIVITY_ATTR |
(package private) static String |
APPENDER_REF_TAG |
(package private) static String |
APPENDER_TAG |
(package private) Hashtable |
appenderBag |
(package private) static String |
CATEGORY |
(package private) static String |
CATEGORY_FACTORY_TAG |
protected LoggerFactory |
catFactory |
(package private) static String |
CLASS_ATTR |
(package private) static String |
CONFIG_DEBUG_ATTR |
(package private) static String |
CONFIGURATION_TAG |
(package private) static String |
dbfKey |
(package private) static String |
EMPTY_STR |
(package private) static String |
ERROR_HANDLER_TAG |
(package private) static String |
FILTER_TAG |
(package private) static String |
INTERNAL_DEBUG_ATTR |
(package private) static String |
LAYOUT_TAG |
(package private) static String |
LEVEL_TAG |
(package private) static String |
LOGGER |
(package private) static String |
LOGGER_FACTORY_TAG |
(package private) static String |
LOGGER_REF |
(package private) static String |
NAME_ATTR |
(package private) static String |
OLD_CONFIGURATION_TAG |
(package private) static Class[] |
ONE_STRING_PARAM |
(package private) static String |
PARAM_TAG |
(package private) static String |
PRIORITY_TAG |
(package private) Properties |
props |
(package private) static String |
REF_ATTR |
(package private) static String |
RENDERED_CLASS_ATTR |
(package private) static String |
RENDERER_TAG |
(package private) static String |
RENDERING_CLASS_ATTR |
(package private) LoggerRepository |
repository |
private static String |
RESET_ATTR |
(package private) static String |
ROOT_REF |
(package private) static String |
ROOT_TAG |
(package private) static String |
THRESHOLD_ATTR |
private static String |
THROWABLE_RENDERER_TAG |
(package private) static String |
VALUE_ATTR |
INHERITED, NULL
Constructor and Description |
---|
DOMConfigurator()
No argument constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
configure(Element element)
Configure log4j using a
configuration element as
defined in the log4j.dtd. |
static void |
configure(String filename)
A static version of
doConfigure(String, LoggerRepository) . |
static void |
configure(URL url)
A static version of
doConfigure(URL, LoggerRepository) . |
static void |
configureAndWatch(String configFilename)
Like
configureAndWatch(String, long) except that the
default delay as defined by FileWatchdog.DEFAULT_DELAY is
used. |
static void |
configureAndWatch(String configFilename,
long delay)
Read the configuration file
configFilename if it
exists. |
private void |
doConfigure(DOMConfigurator.ParseAction action,
LoggerRepository repository) |
void |
doConfigure(Element element,
LoggerRepository repository)
Configure by taking in an DOM element.
|
protected void |
doConfigure(InputSource inputSource,
LoggerRepository repository)
Configure log4j by reading in a log4j.dtd compliant XML
configuration file.
|
void |
doConfigure(InputStream inputStream,
LoggerRepository repository)
Configure log4j by reading in a log4j.dtd compliant XML
configuration file.
|
void |
doConfigure(Reader reader,
LoggerRepository repository)
Configure log4j by reading in a log4j.dtd compliant XML
configuration file.
|
void |
doConfigure(String filename,
LoggerRepository repository) |
void |
doConfigure(URL url,
LoggerRepository repository)
Interpret a resource pointed by a URL and set up log4j accordingly.
|
protected Appender |
findAppenderByName(Document doc,
String appenderName)
Used internally to parse appenders by IDREF name.
|
protected Appender |
findAppenderByReference(Element appenderRef)
Used internally to parse appenders by IDREF element.
|
protected void |
parse(Element element)
Used internally to configure the log4j framework by parsing a DOM
tree of XML elements based on log4j.dtd.
|
protected Appender |
parseAppender(Element appenderElement)
Used internally to parse an appender element.
|
protected void |
parseCategory(Element loggerElement)
Used internally to parse an category element.
|
protected void |
parseCategoryFactory(Element factoryElement)
Used internally to parse the category factory element.
|
protected void |
parseChildrenOfLoggerElement(Element catElement,
Logger cat,
boolean isRoot)
Used internally to parse the children of a category element.
|
static Object |
parseElement(Element element,
Properties props,
Class expectedClass)
Creates an object and processes any nested param elements
but does not call activateOptions.
|
protected void |
parseErrorHandler(Element element,
Appender appender)
Used internally to parse an
ErrorHandler element. |
protected void |
parseFilters(Element element,
Appender appender)
Used internally to parse a filter element.
|
protected Layout |
parseLayout(Element layout_element)
Used internally to parse a layout element.
|
protected void |
parseLevel(Element element,
Logger logger,
boolean isRoot)
Used internally to parse a level element.
|
protected void |
parseRenderer(Element element) |
protected void |
parseRoot(Element rootElement)
Used internally to parse the roor category element.
|
protected ThrowableRenderer |
parseThrowableRenderer(Element element)
Parses throwable renderer.
|
private static void |
parseUnrecognizedElement(Object instance,
Element element,
Properties props)
Delegates unrecognized content to created instance if
it supports UnrecognizedElementParser.
|
private static void |
quietParseUnrecognizedElement(Object instance,
Element element,
Properties props)
Delegates unrecognized content to created instance if
it supports UnrecognizedElementParser and catches and
logs any exception.
|
protected void |
setParameter(Element elem,
PropertySetter propSetter) |
static void |
setParameter(Element elem,
PropertySetter propSetter,
Properties props)
Sets a parameter based from configuration file content.
|
protected String |
subst(String value) |
static String |
subst(String value,
Properties props)
Substitutes property value for any references in expression.
|
static final String CONFIGURATION_TAG
static final String OLD_CONFIGURATION_TAG
static final String RENDERER_TAG
private static final String THROWABLE_RENDERER_TAG
static final String APPENDER_TAG
static final String APPENDER_REF_TAG
static final String PARAM_TAG
static final String LAYOUT_TAG
static final String CATEGORY
static final String LOGGER
static final String LOGGER_REF
static final String CATEGORY_FACTORY_TAG
static final String LOGGER_FACTORY_TAG
static final String NAME_ATTR
static final String CLASS_ATTR
static final String VALUE_ATTR
static final String ROOT_TAG
static final String ROOT_REF
static final String LEVEL_TAG
static final String PRIORITY_TAG
static final String FILTER_TAG
static final String ERROR_HANDLER_TAG
static final String REF_ATTR
static final String ADDITIVITY_ATTR
static final String THRESHOLD_ATTR
static final String CONFIG_DEBUG_ATTR
static final String INTERNAL_DEBUG_ATTR
private static final String RESET_ATTR
static final String RENDERING_CLASS_ATTR
static final String RENDERED_CLASS_ATTR
static final String EMPTY_STR
static final Class[] ONE_STRING_PARAM
static final String dbfKey
Hashtable appenderBag
Properties props
LoggerRepository repository
protected LoggerFactory catFactory
public DOMConfigurator()
protected Appender findAppenderByName(Document doc, String appenderName)
protected Appender findAppenderByReference(Element appenderRef)
private static void parseUnrecognizedElement(Object instance, Element element, Properties props) throws Exception
instance
- instance, may be null.element
- element, may not be null.props
- propertiesIOException
- thrown if configuration of owner object
should be abandoned.Exception
private static void quietParseUnrecognizedElement(Object instance, Element element, Properties props)
instance
- instance, may be null.element
- element, may not be null.props
- propertiesprotected Appender parseAppender(Element appenderElement)
protected void parseErrorHandler(Element element, Appender appender)
ErrorHandler
element.protected void parseFilters(Element element, Appender appender)
protected void parseCategory(Element loggerElement)
protected void parseCategoryFactory(Element factoryElement)
protected void parseRoot(Element rootElement)
protected void parseChildrenOfLoggerElement(Element catElement, Logger cat, boolean isRoot)
protected Layout parseLayout(Element layout_element)
protected void parseRenderer(Element element)
protected ThrowableRenderer parseThrowableRenderer(Element element)
element
- throwableRenderer element.protected void parseLevel(Element element, Logger logger, boolean isRoot)
protected void setParameter(Element elem, PropertySetter propSetter)
public static void configure(Element element)
configuration
element as
defined in the log4j.dtd.public static void configureAndWatch(String configFilename)
configureAndWatch(String, long)
except that the
default delay as defined by FileWatchdog.DEFAULT_DELAY
is
used.configFilename
- A log4j configuration file in XML format.public static void configureAndWatch(String configFilename, long delay)
configFilename
if it
exists. Moreover, a thread will be created that will periodically
check if configFilename
has been created or
modified. The period is determined by the delay
argument. If a change or file creation is detected, then
configFilename
is read to configure log4j.configFilename
- A log4j configuration file in XML format.delay
- The delay in milliseconds to wait between each check.public void doConfigure(String filename, LoggerRepository repository)
public void doConfigure(URL url, LoggerRepository repository)
Configurator
hierarchy
parameter.doConfigure
in interface Configurator
url
- The URL to parserepository
- The hierarchy to operation upon.public void doConfigure(InputStream inputStream, LoggerRepository repository) throws FactoryConfigurationError
doConfigure
in interface Configurator
inputStream
- The InputStream to parserepository
- The hierarchy to operation upon.FactoryConfigurationError
public void doConfigure(Reader reader, LoggerRepository repository) throws FactoryConfigurationError
FactoryConfigurationError
protected void doConfigure(InputSource inputSource, LoggerRepository repository) throws FactoryConfigurationError
FactoryConfigurationError
private final void doConfigure(DOMConfigurator.ParseAction action, LoggerRepository repository) throws FactoryConfigurationError
FactoryConfigurationError
public void doConfigure(Element element, LoggerRepository repository)
public static void configure(String filename) throws FactoryConfigurationError
doConfigure(String, LoggerRepository)
.FactoryConfigurationError
public static void configure(URL url) throws FactoryConfigurationError
doConfigure(URL, LoggerRepository)
.FactoryConfigurationError
protected void parse(Element element)
public static String subst(String value, Properties props)
value
- value from configuration file, may contain
literal text, property references or bothprops
- properties.public static void setParameter(Element elem, PropertySetter propSetter, Properties props)
elem
- param element, may not be null.propSetter
- property setter, may not be null.props
- propertiespublic static Object parseElement(Element element, Properties props, Class expectedClass) throws Exception
element
- element, may not be null.props
- propertiesexpectedClass
- interface or class expected to be implemented
by created classException
- thrown if the contain object should be abandoned.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses