[jboss-svn-commits] JBoss Common SVN: r3203 - jboss-logmanager/trunk/src/main/java/org/jboss/logmanager.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu May 28 20:57:06 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-05-28 20:57:06 -0400 (Thu, 28 May 2009)
New Revision: 3203
Added:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggingMXBeanImpl.java
Modified:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogContext.java
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerNode.java
Log:
JDK logging MXBean support
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogContext.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogContext.java 2009-05-28 10:50:57 UTC (rev 3202)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogContext.java 2009-05-29 00:57:06 UTC (rev 3203)
@@ -22,10 +22,11 @@
package org.jboss.logmanager;
+import java.security.Permission;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
-import java.security.Permission;
+import java.util.logging.LoggingMXBean;
import java.util.logging.LoggingPermission;
/**
@@ -40,6 +41,8 @@
@SuppressWarnings({ "ThisEscapedInObjectConstruction" })
private final LoggerNode rootLogger = new LoggerNode(this);
+ @SuppressWarnings({ "ThisEscapedInObjectConstruction" })
+ private final LoggingMXBean mxBean = new LoggingMXBeanImpl(this);
/**
* This lock is taken any time a change is made which affects multiple nodes in the hierarchy.
@@ -87,6 +90,15 @@
}
/**
+ * Get the {@code LoggingMXBean} associated with this log context.
+ *
+ * @return the {@code LoggingMXBean} instance
+ */
+ public LoggingMXBean getMxBean() {
+ return mxBean;
+ }
+
+ /**
* Get the system log context.
*
* @return the system log context
@@ -95,12 +107,17 @@
return SYSTEM_CONTEXT;
}
- private static volatile LogContextSelector logContextSelector = new LogContextSelector() {
+ /**
+ * The default log context selector, which always returns the system log context.
+ */
+ public static final LogContextSelector DEFAULT_LOG_CONTEXT_SELECTOR = new LogContextSelector() {
public LogContext getLogContext() {
return SYSTEM_CONTEXT;
}
};
+ private static volatile LogContextSelector logContextSelector = DEFAULT_LOG_CONTEXT_SELECTOR;
+
/**
* Get the currently active log context.
*
@@ -133,4 +150,8 @@
sm.checkPermission(CONTROL_PERMISSION);
}
}
+
+ LoggerNode getRootLoggerNode() {
+ return rootLogger;
+ }
}
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java 2009-05-28 10:50:57 UTC (rev 3202)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java 2009-05-29 00:57:06 UTC (rev 3203)
@@ -74,6 +74,18 @@
} catch (Exception e) {
// ignore; just skip it
}
+ /* Next hack: Replace the crappy MXBean on the system logmanager, if it's there.
+ */
+ final Class<java.util.logging.LogManager> lmc = java.util.logging.LogManager.class;
+ try {
+ synchronized (lmc) {
+ final Field loggingMXBean = lmc.getDeclaredField("loggingMXBean");
+ loggingMXBean.setAccessible(true);
+ loggingMXBean.set(null, LogContext.getSystemLogContext().getMxBean());
+ }
+ } catch (Exception e) {
+ // ignore; just skip it
+ }
return null;
}
});
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerNode.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerNode.java 2009-05-28 10:50:57 UTC (rev 3202)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggerNode.java 2009-05-29 00:57:06 UTC (rev 3203)
@@ -23,9 +23,10 @@
package org.jboss.logmanager;
import java.lang.ref.WeakReference;
+import java.util.Collection;
import java.util.concurrent.ConcurrentMap;
+import static org.jboss.logmanager.ConcurrentReferenceHashMap.ReferenceType.STRONG;
import static org.jboss.logmanager.ConcurrentReferenceHashMap.ReferenceType.WEAK;
-import static org.jboss.logmanager.ConcurrentReferenceHashMap.ReferenceType.STRONG;
/**
* A node in the tree of logger names. Maintains weak references to children and a strong reference to its parent.
@@ -169,6 +170,15 @@
}
/**
+ * Get the children of this logger.
+ *
+ * @return the children
+ */
+ Collection<LoggerNode> getChildren() {
+ return children.values();
+ }
+
+ /**
* Return the logger instance of the parent logger node, or {@code null} if this is the root logger node.
*
* @return the parent logger instance, or {@code null} for none
Added: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggingMXBeanImpl.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggingMXBeanImpl.java (rev 0)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LoggingMXBeanImpl.java 2009-05-29 00:57:06 UTC (rev 3203)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.logmanager;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import java.util.logging.Level;
+import java.util.logging.LoggingMXBean;
+
+final class LoggingMXBeanImpl implements LoggingMXBean {
+ private final LogContext context;
+
+ LoggingMXBeanImpl(final LogContext context) {
+ this.context = context;
+ }
+
+ private void getAllNames(List<String> names, LoggerNode node) {
+ final Logger logger = node.getLogger();
+ if (logger != null) {
+ names.add(logger.getName());
+ }
+ for (LoggerNode loggerNode : node.getChildren()) {
+ getAllNames(names, loggerNode);
+ }
+ }
+
+ public List<String> getLoggerNames() {
+ final LoggerNode node = context.getRootLoggerNode();
+ final ArrayList<String> names = new ArrayList<String>();
+ getAllNames(names, node);
+ return names;
+ }
+
+ public String getLoggerLevel(final String loggerName) {
+ final Logger logger = context.getLoggerIfExists(loggerName);
+ final Level level = logger == null ? null : logger.getLevel();
+ return level == null ? "" : level.getName();
+ }
+
+ public void setLoggerLevel(final String loggerName, final String levelName) {
+ final Logger logger = context.getLoggerIfExists(loggerName);
+ if (logger == null) {
+ throw new IllegalArgumentException("logger \"" + loggerName + "\" does not exist");
+ }
+ logger.setLevel(levelName == null ? null : Level.parse(levelName));
+ }
+
+ public String getParentLoggerName(final String loggerName) {
+ final Logger logger = context.getLoggerIfExists(loggerName);
+ if (logger == null) {
+ return null;
+ }
+ final Logger parent = logger.getParent();
+ return parent == null ? "" : parent.getName();
+ }
+}
More information about the jboss-svn-commits
mailing list