Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic setting of Log4j level across multiple JVMs

Tags:

java

log4j

jmx

I am working in an application has a number of plain vanilla Java components, each of which runs in a separate JVM. All these components use Log4j and there is no option to change to another logging library.

As the title implies, I am looking for an "easy" way to dynamically apply a Log4j logging level across all components/JVMs. By "easy", I mean without rewriting the source code (otherwise, one can use, for instance, an interface to get/set the logging level, and have all classes implement that interface).

There are articles on the web about using JMX (for instance, via the LoggerDynamicBean class (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/jmx/LoggerDynamicMBean.html) of the Log4j distribution.

An interesting such article describes how to implement this using an application server (Tomcat): http://www.devx.com/Java/Article/32359/1954. The application server seems necessary as an implementation of the MBeanServer class, to which all the loggers will be registered by Log4j as MBeans.

Is there any implementation that does this dynamic logging level setting, across multiple JVMs, either via JMX, or via any other means?

like image 735
PNS Avatar asked Nov 26 '25 02:11

PNS


1 Answers

Keep it simple. Point all the JVMs to the same log4j configuration file use this to have them reload occasionally.

PropertyConfigurator.configureAndWatch( yourConfigFile, yourReloadInterval);

like image 123
digitaljoel Avatar answered Nov 28 '25 17:11

digitaljoel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!