Package org.apache.log4j.xml
Class DOMConfigurator
java.lang.Object
org.apache.log4j.xml.DOMConfigurator
- All Implemented Interfaces:
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 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.
- Since:
- 0.8.3
- Author:
- Christopher Taylor, Ceki Gülcü, Anders Kristensen
-
Field Summary
FieldsFields inherited from interface org.apache.log4j.spi.Configurator
INHERITED, NULL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidA static version ofdoConfigure(String, LoggerRepository).static voidA static version ofdoConfigure(URL, LoggerRepository).static voidConfigure log4j using aconfigurationelement as defined in the log4j.dtd.static voidconfigureAndWatch(String configFilename) LikeconfigureAndWatch(String, long)except that the default delay as defined byFileWatchdog.DEFAULT_DELAYis used.static voidconfigureAndWatch(String configFilename, long delay) Read the configuration fileconfigFilenameif it exists.voiddoConfigure(InputStream inputStream, LoggerRepository repository) Configure log4j by reading in a log4j.dtd compliant XML configuration file.voiddoConfigure(Reader reader, LoggerRepository repository) Configure log4j by reading in a log4j.dtd compliant XML configuration file.voiddoConfigure(String filename, LoggerRepository repository) voiddoConfigure(URL url, LoggerRepository repository) Interpret a resource pointed by a URL and set up log4j accordingly.voiddoConfigure(Element element, LoggerRepository repository) Configure by taking in an DOM element.protected voiddoConfigure(InputSource inputSource, LoggerRepository repository) Configure log4j by reading in a log4j.dtd compliant XML configuration file.protected AppenderfindAppenderByName(Document doc, String appenderName) Used internally to parse appenders by IDREF name.protected AppenderfindAppenderByReference(Element appenderRef) Used internally to parse appenders by IDREF element.protected voidUsed internally to configure the log4j framework by parsing a DOM tree of XML elements based on log4j.dtd.protected AppenderparseAppender(Element appenderElement) Used internally to parse an appender element.protected voidparseCategory(Element loggerElement) Used internally to parse an category element.protected voidparseCategoryFactory(Element factoryElement) Used internally to parse the category factory element.protected voidparseChildrenOfLoggerElement(Element catElement, Logger cat, boolean isRoot) Used internally to parse the children of a category element.static ObjectparseElement(Element element, Properties props, Class expectedClass) Creates an object and processes any nested param elements but does not call activateOptions.protected voidparseErrorHandler(Element element, Appender appender) Used internally to parse anErrorHandlerelement.protected voidparseFilters(Element element, Appender appender) Used internally to parse a filter element.protected LayoutparseLayout(Element layout_element) Used internally to parse a layout element.protected voidparseLevel(Element element, Logger logger, boolean isRoot) Used internally to parse a level element.protected voidparseRenderer(Element element) protected voidUsed internally to parse the roor category element.protected ThrowableRendererparseThrowableRenderer(Element element) Parses throwable renderer.protected voidsetParameter(Element elem, PropertySetter propSetter) static voidsetParameter(Element elem, PropertySetter propSetter, Properties props) Sets a parameter based from configuration file content.protected Stringstatic Stringsubst(String value, Properties props) Substitutes property value for any references in expression.
-
Field Details
-
catFactory
-
-
Constructor Details
-
DOMConfigurator
public DOMConfigurator()No argument constructor.
-
-
Method Details
-
findAppenderByName
Used internally to parse appenders by IDREF name. -
findAppenderByReference
Used internally to parse appenders by IDREF element. -
parseAppender
Used internally to parse an appender element. -
parseErrorHandler
Used internally to parse anErrorHandlerelement. -
parseFilters
Used internally to parse a filter element. -
parseCategory
Used internally to parse an category element. -
parseCategoryFactory
Used internally to parse the category factory element. -
parseRoot
Used internally to parse the roor category element. -
parseChildrenOfLoggerElement
Used internally to parse the children of a category element. -
parseLayout
Used internally to parse a layout element. -
parseRenderer
-
parseThrowableRenderer
Parses throwable renderer.- Parameters:
element- throwableRenderer element.- Returns:
- configured throwable renderer.
- Since:
- 1.2.16.
-
parseLevel
Used internally to parse a level element. -
setParameter
-
configure
Configure log4j using aconfigurationelement as defined in the log4j.dtd. -
configureAndWatch
LikeconfigureAndWatch(String, long)except that the default delay as defined byFileWatchdog.DEFAULT_DELAYis used.- Parameters:
configFilename- A log4j configuration file in XML format.
-
configureAndWatch
Read the configuration fileconfigFilenameif it exists. Moreover, a thread will be created that will periodically check ifconfigFilenamehas been created or modified. The period is determined by thedelayargument. If a change or file creation is detected, thenconfigFilenameis read to configure log4j.- Parameters:
configFilename- A log4j configuration file in XML format.delay- The delay in milliseconds to wait between each check.
-
doConfigure
-
doConfigure
Description copied from interface:ConfiguratorInterpret a resource pointed by a URL and set up log4j accordingly.The configuration is done relative to the
hierarchyparameter.- Specified by:
doConfigurein interfaceConfigurator- Parameters:
url- The URL to parserepository- The hierarchy to operation upon.
-
doConfigure
public void doConfigure(InputStream inputStream, LoggerRepository repository) throws FactoryConfigurationError Configure log4j by reading in a log4j.dtd compliant XML configuration file.- Specified by:
doConfigurein interfaceConfigurator- Parameters:
inputStream- The InputStream to parserepository- The hierarchy to operation upon.- Throws:
FactoryConfigurationError
-
doConfigure
public void doConfigure(Reader reader, LoggerRepository repository) throws FactoryConfigurationError Configure log4j by reading in a log4j.dtd compliant XML configuration file.- Throws:
FactoryConfigurationError
-
doConfigure
protected void doConfigure(InputSource inputSource, LoggerRepository repository) throws FactoryConfigurationError Configure log4j by reading in a log4j.dtd compliant XML configuration file.- Throws:
FactoryConfigurationError
-
doConfigure
Configure by taking in an DOM element. -
configure
A static version ofdoConfigure(String, LoggerRepository).- Throws:
FactoryConfigurationError
-
configure
A static version ofdoConfigure(URL, LoggerRepository).- Throws:
FactoryConfigurationError
-
parse
Used internally to configure the log4j framework by parsing a DOM tree of XML elements based on log4j.dtd. -
subst
-
subst
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
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 Object parseElement(Element element, Properties props, Class expectedClass) throws 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:
Exception- thrown if the contain object should be abandoned.- Since:
- 1.2.15
-