You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2020/03/01 05:44:45 UTC
[zookeeper] branch branch-3.5 updated: ZOOKEEPER-3737: Detect log4j
1.2 jmx support better
This is an automated email from the ASF dual-hosted git repository.
phunt pushed a commit to branch branch-3.5
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/branch-3.5 by this push:
new 1332b0d ZOOKEEPER-3737: Detect log4j 1.2 jmx support better
1332b0d is described below
commit 1332b0d049f60239cc3001f9bf49b83444ec8cab
Author: Christopher Tubbs <ct...@apache.org>
AuthorDate: Sat Feb 29 21:42:47 2020 -0800
ZOOKEEPER-3737: Detect log4j 1.2 jmx support better
* Look for jmx class that exists only in the log4j 1.2 jar, but not in
the log4j2 1.2 compatibility jar.
* Check if disabled before attempting to detect log4j 1.2 jmx classes.
* Update log messages to highlight that they are referring to log4j 1.2
and not log4j2 or other versions.
* Minor javadoc fixup
Author: Christopher Tubbs <ct...@apache.org>
Reviewers: phunt@apache.org
Closes #1270 from ctubbsii/ZK-3737
Change-Id: I7ebd7a28386d3fee33fcc9078d7f573dc766e8ee
(cherry picked from commit 5a2332058deba04313ad37fa05cbb1515c83b8e6)
Signed-off-by: Patrick Hunt <ph...@apache.org>
---
.../java/org/apache/zookeeper/jmx/ManagedUtil.java | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java b/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java
index 04b5bdd..7af07a0 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/jmx/ManagedUtil.java
@@ -36,18 +36,16 @@ public class ManagedUtil {
private static boolean isLog4jJmxEnabled() {
boolean enabled = false;
- try {
- Class.forName("org.apache.log4j.spi.LoggerRepository");
-
- if (Boolean.getBoolean("zookeeper.jmx.log4j.disable")) {
- LOG.info("Log4j found but jmx support is disabled.");
- } else {
+ if (Boolean.getBoolean("zookeeper.jmx.log4j.disable")) {
+ LOG.info("Log4j 1.2 jmx support is disabled by property.");
+ } else {
+ try {
+ Class.forName("org.apache.log4j.jmx.HierarchyDynamicMBean");
enabled = true;
- LOG.info("Log4j found with jmx enabled.");
+ LOG.info("Log4j 1.2 jmx support found and enabled.");
+ } catch (ClassNotFoundException e) {
+ LOG.info("Log4j 1.2 jmx support not found; jmx disabled.");
}
-
- } catch (ClassNotFoundException e) {
- LOG.info("Log4j not found.");
}
return enabled;
@@ -55,7 +53,7 @@ public class ManagedUtil {
/**
- * Register the log4j JMX mbeans. Set environment variable
+ * Register the log4j JMX mbeans. Set system property
* "zookeeper.jmx.log4j.disable" to true to disable registration.
* @see http://logging.apache.org/log4j/1.2/apidocs/index.html?org/apache/log4j/jmx/package-summary.html
* @throws JMException if registration fails
@@ -112,7 +110,7 @@ public class ManagedUtil {
.invoke(hdm, loggerName);
}
} catch (Exception e) {
- LOG.error("Problems while registering log4j jmx beans!", e);
+ LOG.error("Problems while registering log4j 1.2 jmx beans!", e);
throw new JMException(e.toString());
}
}