Package org.apache.log4j.xml
Class DOMConfigurator
- java.lang.Object
-
- org.apache.log4j.xml.DOMConfigurator
-
- All Implemented Interfaces:
Configurator
public class DOMConfigurator extends java.lang.Object implements Configurator
Use this class to initialize the log4j environment using a DOM tree.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 thelog4j: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.
- Since:
- 0.8.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
DOMConfigurator.ParseAction
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.lang.String
ADDITIVITY_ATTR
(package private) static java.lang.String
APPENDER_REF_TAG
(package private) static java.lang.String
APPENDER_TAG
(package private) java.util.Hashtable
appenderBag
(package private) static java.lang.String
CATEGORY
(package private) static java.lang.String
CATEGORY_FACTORY_TAG
protected LoggerFactory
catFactory
(package private) static java.lang.String
CLASS_ATTR
(package private) static java.lang.String
CONFIG_DEBUG_ATTR
(package private) static java.lang.String
CONFIGURATION_TAG
(package private) static java.lang.String
dbfKey
(package private) static java.lang.String
EMPTY_STR
(package private) static java.lang.String
ERROR_HANDLER_TAG
(package private) static java.lang.String
FILTER_TAG
(package private) static java.lang.String
INTERNAL_DEBUG_ATTR
(package private) static java.lang.String
LAYOUT_TAG
(package private) static java.lang.String
LEVEL_TAG
(package private) static java.lang.String
LOGGER
(package private) static java.lang.String
LOGGER_FACTORY_TAG
(package private) static java.lang.String
LOGGER_REF
(package private) static java.lang.String
NAME_ATTR
(package private) static java.lang.String
OLD_CONFIGURATION_TAG
(package private) static java.lang.Class[]
ONE_STRING_PARAM
(package private) static java.lang.String
PARAM_TAG
(package private) static java.lang.String
PRIORITY_TAG
(package private) java.util.Properties
props
(package private) static java.lang.String
REF_ATTR
(package private) static java.lang.String
RENDERED_CLASS_ATTR
(package private) static java.lang.String
RENDERER_TAG
(package private) static java.lang.String
RENDERING_CLASS_ATTR
(package private) LoggerRepository
repository
private static java.lang.String
RESET_ATTR
(package private) static java.lang.String
ROOT_REF
(package private) static java.lang.String
ROOT_TAG
(package private) static java.lang.String
THRESHOLD_ATTR
private static java.lang.String
THROWABLE_RENDERER_TAG
(package private) static java.lang.String
VALUE_ATTR
-
Fields inherited from interface org.apache.log4j.spi.Configurator
INHERITED, NULL
-
-
Constructor Summary
Constructors Constructor Description DOMConfigurator()
No argument constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
configure(java.lang.String filename)
A static version ofdoConfigure(String, LoggerRepository)
.static void
configure(java.net.URL url)
A static version ofdoConfigure(URL, LoggerRepository)
.static void
configure(org.w3c.dom.Element element)
Configure log4j using aconfiguration
element as defined in the log4j.dtd.static void
configureAndWatch(java.lang.String configFilename)
LikeconfigureAndWatch(String, long)
except that the default delay as defined byFileWatchdog.DEFAULT_DELAY
is used.static void
configureAndWatch(java.lang.String configFilename, long delay)
Read the configuration fileconfigFilename
if it exists.void
doConfigure(java.io.InputStream inputStream, LoggerRepository repository)
Configure log4j by reading in a log4j.dtd compliant XML configuration file.void
doConfigure(java.io.Reader reader, LoggerRepository repository)
Configure log4j by reading in a log4j.dtd compliant XML configuration file.void
doConfigure(java.lang.String filename, LoggerRepository repository)
void
doConfigure(java.net.URL url, LoggerRepository repository)
Interpret a resource pointed by a URL and set up log4j accordingly.private void
doConfigure(DOMConfigurator.ParseAction action, LoggerRepository repository)
void
doConfigure(org.w3c.dom.Element element, LoggerRepository repository)
Configure by taking in an DOM element.protected void
doConfigure(org.xml.sax.InputSource inputSource, LoggerRepository repository)
Configure log4j by reading in a log4j.dtd compliant XML configuration file.protected Appender
findAppenderByName(org.w3c.dom.Document doc, java.lang.String appenderName)
Used internally to parse appenders by IDREF name.protected Appender
findAppenderByReference(org.w3c.dom.Element appenderRef)
Used internally to parse appenders by IDREF element.protected void
parse(org.w3c.dom.Element element)
Used internally to configure the log4j framework by parsing a DOM tree of XML elements based on log4j.dtd.protected Appender
parseAppender(org.w3c.dom.Element appenderElement)
Used internally to parse an appender element.protected void
parseCategory(org.w3c.dom.Element loggerElement)
Used internally to parse an category element.protected void
parseCategoryFactory(org.w3c.dom.Element factoryElement)
Used internally to parse the category factory element.protected void
parseChildrenOfLoggerElement(org.w3c.dom.Element catElement, Logger cat, boolean isRoot)
Used internally to parse the children of a category element.static java.lang.Object
parseElement(org.w3c.dom.Element element, java.util.Properties props, java.lang.Class expectedClass)
Creates an object and processes any nested param elements but does not call activateOptions.protected void
parseErrorHandler(org.w3c.dom.Element element, Appender appender)
Used internally to parse anErrorHandler
element.protected void
parseFilters(org.w3c.dom.Element element, Appender appender)
Used internally to parse a filter element.protected Layout
parseLayout(org.w3c.dom.Element layout_element)
Used internally to parse a layout element.protected void
parseLevel(org.w3c.dom.Element element, Logger logger, boolean isRoot)
Used internally to parse a level element.protected void
parseRenderer(org.w3c.dom.Element element)
protected void
parseRoot(org.w3c.dom.Element rootElement)
Used internally to parse the roor category element.protected ThrowableRenderer
parseThrowableRenderer(org.w3c.dom.Element element)
Parses throwable renderer.private static void
parseUnrecognizedElement(java.lang.Object instance, org.w3c.dom.Element element, java.util.Properties props)
Delegates unrecognized content to created instance if it supports UnrecognizedElementParser.private static void
quietParseUnrecognizedElement(java.lang.Object instance, org.w3c.dom.Element element, java.util.Properties props)
Delegates unrecognized content to created instance if it supports UnrecognizedElementParser and catches and logs any exception.protected void
setParameter(org.w3c.dom.Element elem, PropertySetter propSetter)
static void
setParameter(org.w3c.dom.Element elem, PropertySetter propSetter, java.util.Properties props)
Sets a parameter based from configuration file content.protected java.lang.String
subst(java.lang.String value)
static java.lang.String
subst(java.lang.String value, java.util.Properties props)
Substitutes property value for any references in expression.
-
-
-
Field Detail
-
CONFIGURATION_TAG
static final java.lang.String CONFIGURATION_TAG
- See Also:
- Constant Field Values
-
OLD_CONFIGURATION_TAG
static final java.lang.String OLD_CONFIGURATION_TAG
- See Also:
- Constant Field Values
-
RENDERER_TAG
static final java.lang.String RENDERER_TAG
- See Also:
- Constant Field Values
-
THROWABLE_RENDERER_TAG
private static final java.lang.String THROWABLE_RENDERER_TAG
- See Also:
- Constant Field Values
-
APPENDER_TAG
static final java.lang.String APPENDER_TAG
- See Also:
- Constant Field Values
-
APPENDER_REF_TAG
static final java.lang.String APPENDER_REF_TAG
- See Also:
- Constant Field Values
-
PARAM_TAG
static final java.lang.String PARAM_TAG
- See Also:
- Constant Field Values
-
LAYOUT_TAG
static final java.lang.String LAYOUT_TAG
- See Also:
- Constant Field Values
-
CATEGORY
static final java.lang.String CATEGORY
- See Also:
- Constant Field Values
-
LOGGER
static final java.lang.String LOGGER
- See Also:
- Constant Field Values
-
LOGGER_REF
static final java.lang.String LOGGER_REF
- See Also:
- Constant Field Values
-
CATEGORY_FACTORY_TAG
static final java.lang.String CATEGORY_FACTORY_TAG
- See Also:
- Constant Field Values
-
LOGGER_FACTORY_TAG
static final java.lang.String LOGGER_FACTORY_TAG
- See Also:
- Constant Field Values
-
NAME_ATTR
static final java.lang.String NAME_ATTR
- See Also:
- Constant Field Values
-
CLASS_ATTR
static final java.lang.String CLASS_ATTR
- See Also:
- Constant Field Values
-
VALUE_ATTR
static final java.lang.String VALUE_ATTR
- See Also:
- Constant Field Values
-
ROOT_TAG
static final java.lang.String ROOT_TAG
- See Also:
- Constant Field Values
-
ROOT_REF
static final java.lang.String ROOT_REF
- See Also:
- Constant Field Values
-
LEVEL_TAG
static final java.lang.String LEVEL_TAG
- See Also:
- Constant Field Values
-
PRIORITY_TAG
static final java.lang.String PRIORITY_TAG
- See Also:
- Constant Field Values
-
FILTER_TAG
static final java.lang.String FILTER_TAG
- See Also:
- Constant Field Values
-
ERROR_HANDLER_TAG
static final java.lang.String ERROR_HANDLER_TAG
- See Also:
- Constant Field Values
-
REF_ATTR
static final java.lang.String REF_ATTR
- See Also:
- Constant Field Values
-
ADDITIVITY_ATTR
static final java.lang.String ADDITIVITY_ATTR
- See Also:
- Constant Field Values
-
THRESHOLD_ATTR
static final java.lang.String THRESHOLD_ATTR
- See Also:
- Constant Field Values
-
CONFIG_DEBUG_ATTR
static final java.lang.String CONFIG_DEBUG_ATTR
- See Also:
- Constant Field Values
-
INTERNAL_DEBUG_ATTR
static final java.lang.String INTERNAL_DEBUG_ATTR
- See Also:
- Constant Field Values
-
RESET_ATTR
private static final java.lang.String RESET_ATTR
- See Also:
- Constant Field Values
-
RENDERING_CLASS_ATTR
static final java.lang.String RENDERING_CLASS_ATTR
- See Also:
- Constant Field Values
-
RENDERED_CLASS_ATTR
static final java.lang.String RENDERED_CLASS_ATTR
- See Also:
- Constant Field Values
-
EMPTY_STR
static final java.lang.String EMPTY_STR
- See Also:
- Constant Field Values
-
ONE_STRING_PARAM
static final java.lang.Class[] ONE_STRING_PARAM
-
dbfKey
static final java.lang.String dbfKey
- See Also:
- Constant Field Values
-
appenderBag
java.util.Hashtable appenderBag
-
props
java.util.Properties props
-
repository
LoggerRepository repository
-
catFactory
protected LoggerFactory catFactory
-
-
Method Detail
-
findAppenderByName
protected Appender findAppenderByName(org.w3c.dom.Document doc, java.lang.String appenderName)
Used internally to parse appenders by IDREF name.
-
findAppenderByReference
protected Appender findAppenderByReference(org.w3c.dom.Element appenderRef)
Used internally to parse appenders by IDREF element.
-
parseUnrecognizedElement
private static void parseUnrecognizedElement(java.lang.Object instance, org.w3c.dom.Element element, java.util.Properties props) throws java.lang.Exception
Delegates unrecognized content to created instance if it supports UnrecognizedElementParser.- Parameters:
instance
- instance, may be null.element
- element, may not be null.props
- properties- Throws:
java.io.IOException
- thrown if configuration of owner object should be abandoned.java.lang.Exception
- Since:
- 1.2.15
-
quietParseUnrecognizedElement
private static void quietParseUnrecognizedElement(java.lang.Object instance, org.w3c.dom.Element element, java.util.Properties props)
Delegates unrecognized content to created instance if it supports UnrecognizedElementParser and catches and logs any exception.- Parameters:
instance
- instance, may be null.element
- element, may not be null.props
- properties- Since:
- 1.2.15
-
parseAppender
protected Appender parseAppender(org.w3c.dom.Element appenderElement)
Used internally to parse an appender element.
-
parseErrorHandler
protected void parseErrorHandler(org.w3c.dom.Element element, Appender appender)
Used internally to parse anErrorHandler
element.
-
parseFilters
protected void parseFilters(org.w3c.dom.Element element, Appender appender)
Used internally to parse a filter element.
-
parseCategory
protected void parseCategory(org.w3c.dom.Element loggerElement)
Used internally to parse an category element.
-
parseCategoryFactory
protected void parseCategoryFactory(org.w3c.dom.Element factoryElement)
Used internally to parse the category factory element.
-
parseRoot
protected void parseRoot(org.w3c.dom.Element rootElement)
Used internally to parse the roor category element.
-
parseChildrenOfLoggerElement
protected void parseChildrenOfLoggerElement(org.w3c.dom.Element catElement, Logger cat, boolean isRoot)
Used internally to parse the children of a category element.
-
parseLayout
protected Layout parseLayout(org.w3c.dom.Element layout_element)
Used internally to parse a layout element.
-
parseRenderer
protected void parseRenderer(org.w3c.dom.Element element)
-
parseThrowableRenderer
protected ThrowableRenderer parseThrowableRenderer(org.w3c.dom.Element element)
Parses throwable renderer.- Parameters:
element
- throwableRenderer element.- Returns:
- configured throwable renderer.
- Since:
- 1.2.16.
-
parseLevel
protected void parseLevel(org.w3c.dom.Element element, Logger logger, boolean isRoot)
Used internally to parse a level element.
-
setParameter
protected void setParameter(org.w3c.dom.Element elem, PropertySetter propSetter)
-
configure
public static void configure(org.w3c.dom.Element element)
Configure log4j using aconfiguration
element as defined in the log4j.dtd.
-
configureAndWatch
public static void configureAndWatch(java.lang.String configFilename)
LikeconfigureAndWatch(String, long)
except that the default delay as defined byFileWatchdog.DEFAULT_DELAY
is used.- Parameters:
configFilename
- A log4j configuration file in XML format.
-
configureAndWatch
public static void configureAndWatch(java.lang.String configFilename, long delay)
Read the configuration fileconfigFilename
if it exists. Moreover, a thread will be created that will periodically check ifconfigFilename
has been created or modified. The period is determined by thedelay
argument. If a change or file creation is detected, thenconfigFilename
is read to configure log4j.- Parameters:
configFilename
- A log4j configuration file in XML format.delay
- The delay in milliseconds to wait between each check.
-
doConfigure
public void doConfigure(java.lang.String filename, LoggerRepository repository)
-
doConfigure
public void doConfigure(java.net.URL url, LoggerRepository repository)
Description copied from interface:Configurator
Interpret a resource pointed by a URL and set up log4j accordingly. The configuration is done relative to thehierarchy
parameter.- Specified by:
doConfigure
in interfaceConfigurator
- Parameters:
url
- The URL to parserepository
- The hierarchy to operation upon.
-
doConfigure
public void doConfigure(java.io.InputStream inputStream, LoggerRepository repository) throws javax.xml.parsers.FactoryConfigurationError
Configure log4j by reading in a log4j.dtd compliant XML configuration file.- Specified by:
doConfigure
in interfaceConfigurator
- Parameters:
inputStream
- The InputStream to parserepository
- The hierarchy to operation upon.- Throws:
javax.xml.parsers.FactoryConfigurationError
-
doConfigure
public void doConfigure(java.io.Reader reader, LoggerRepository repository) throws javax.xml.parsers.FactoryConfigurationError
Configure log4j by reading in a log4j.dtd compliant XML configuration file.- Throws:
javax.xml.parsers.FactoryConfigurationError
-
doConfigure
protected void doConfigure(org.xml.sax.InputSource inputSource, LoggerRepository repository) throws javax.xml.parsers.FactoryConfigurationError
Configure log4j by reading in a log4j.dtd compliant XML configuration file.- Throws:
javax.xml.parsers.FactoryConfigurationError
-
doConfigure
private final void doConfigure(DOMConfigurator.ParseAction action, LoggerRepository repository) throws javax.xml.parsers.FactoryConfigurationError
- Throws:
javax.xml.parsers.FactoryConfigurationError
-
doConfigure
public void doConfigure(org.w3c.dom.Element element, LoggerRepository repository)
Configure by taking in an DOM element.
-
configure
public static void configure(java.lang.String filename) throws javax.xml.parsers.FactoryConfigurationError
A static version ofdoConfigure(String, LoggerRepository)
.- Throws:
javax.xml.parsers.FactoryConfigurationError
-
configure
public static void configure(java.net.URL url) throws javax.xml.parsers.FactoryConfigurationError
A static version ofdoConfigure(URL, LoggerRepository)
.- Throws:
javax.xml.parsers.FactoryConfigurationError
-
parse
protected void parse(org.w3c.dom.Element element)
Used internally to configure the log4j framework by parsing a DOM tree of XML elements based on log4j.dtd.
-
subst
protected java.lang.String subst(java.lang.String value)
-
subst
public static java.lang.String subst(java.lang.String value, java.util.Properties props)
Substitutes property value for any references in expression.- Parameters:
value
- value from configuration file, may contain literal text, property references or bothprops
- properties.- Returns:
- evaluated expression, may still contain expressions if unable to expand.
- Since:
- 1.2.15
-
setParameter
public static void setParameter(org.w3c.dom.Element elem, PropertySetter propSetter, java.util.Properties props)
Sets a parameter based from configuration file content.- Parameters:
elem
- param element, may not be null.propSetter
- property setter, may not be null.props
- properties- Since:
- 1.2.15
-
parseElement
public static java.lang.Object parseElement(org.w3c.dom.Element element, java.util.Properties props, java.lang.Class expectedClass) throws java.lang.Exception
Creates an object and processes any nested param elements but does not call activateOptions. If the class also supports UnrecognizedElementParser, the parseUnrecognizedElement method will be call for any child elements other than param.- Parameters:
element
- element, may not be null.props
- propertiesexpectedClass
- interface or class expected to be implemented by created class- Returns:
- created class or null.
- Throws:
java.lang.Exception
- thrown if the contain object should be abandoned.- Since:
- 1.2.15
-
-