This post describes how log4j can be configured outside of the application and also changed at runtime.
File Watchdog
Log4j provides runtime configuration through theDOMConfigurator.configureAndWatch
for XML files, or the PropertyConfigurator.configureAndWatch
for properties file. Both these methods take the absolute path for the configuration file and a refresh interval. This allows the configuration file to be located outside of a web application war file and allow administrators to change the logging levels at runtime.The
configureAndWatch
API can be invoked from a custom servlet listener. For users of the Spring framework, there already exists the Log4jConfigListener
that is a wrapper to the Log4j configureAndWatch
API. This listener is configured in the web applications web.xml.Spring Log4jConfigListener |
By specifying the
log4jConfigLocation
to a file outside the web application, it allows different environments (dev, test, prod) to have different levels of logging enabled. The log4jRefreshInterval
specifies how often the log4j.properties file should be checked for changes and reloaded. This allows runtime changes to the log4j configuration to be performed.JMX
Log4j also has built-in support for JMX and two classesorg.apache.log4j.jmx.LoggerDynamicMBean
and org.apache.log4j.HierarchyDynamicMBean
are used to expose and register loggers as MBeans. However, it still requires wrappers to work to add loggers that are not defined at start-up.
No comments:
Post a Comment