我正在开发的应用程序有许多普通的 Java 组件,每个组件都在单独的 JVM 中运行。所有这些组件都使用 Log4j,并且无法更改为其他日志记录库。
正如标题所暗示的,我正在寻找一种“简单”的方法来在所有组件/JVM 上动态应用 Log4j 日志记录级别。我所说的“简单”是指无需重写源代码(否则,可以使用例如接口来获取/设置日志记录级别,并让所有类实现该接口)。
网上有一些关于使用 JMX 的文章(例如,通过 LoggerDynamicBean 类 (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/jmx/LoggerDynamicMBean.html)
一篇有趣的文章介绍了如何使用应用程序服务器 (Tomcat) 实现此操作:http://www.devx.com/Java/Article/32359/1954 应用程序服务器作为 MBeanServer 类的实现似乎是必要的,所有记录器都将注册到该类。 Log4j 作为 MBean。
是否有任何实现可以通过 JMX 或任何其他方式跨多个 JVM 进行动态日志记录级别设置?
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?
发布评论
评论(1)
保持简单。将所有 JVM 指向同一个 log4j 配置文件,使用此文件偶尔会重新加载它们。
PropertyConfigurator.configureAndWatch( yourConfigFile, yourReloadInterval);
Keep it simple. Point all the JVMs to the same log4j configuration file use this to have them reload occasionally.
PropertyConfigurator.configureAndWatch( yourConfigFile, yourReloadInterval);