diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2006-09-19 16:23:34 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2006-09-19 16:23:34 +0000 |
commit | 19db9631bc261c09a592f20e68e1a72a78e646de (patch) | |
tree | ff3746b7de8d5e229356b1f899cbdc091d56636b /libjava | |
parent | 7ab629664b6fae00406eeb8b662802b39b5d0f70 (diff) | |
download | gcc-19db9631bc261c09a592f20e68e1a72a78e646de.zip gcc-19db9631bc261c09a592f20e68e1a72a78e646de.tar.gz gcc-19db9631bc261c09a592f20e68e1a72a78e646de.tar.bz2 |
[multiple changes]
2006-09-19 Mark Wielaard <mark@klomp.org>
Fixes bug #29137
* java/util/logging/LogManager.java (addLogger): Always check for
existing children of a new Logger.
2006-09-19 Tom Tromey <tromey@redhat.com>
* java/util/logging/LogManager.java: Re-merged with Classpath.
From-SVN: r117058
Diffstat (limited to 'libjava')
-rw-r--r-- | libjava/ChangeLog | 10 | ||||
-rw-r--r-- | libjava/java/util/logging/LogManager.java | 113 |
2 files changed, 101 insertions, 22 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 92cbfb7..27f582d 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,13 @@ +2006-09-19 Mark Wielaard <mark@klomp.org> + + Fixes bug #29137 + * java/util/logging/LogManager.java (addLogger): Always check for + existing children of a new Logger. + +2006-09-19 Tom Tromey <tromey@redhat.com> + + * java/util/logging/LogManager.java: Re-merged with Classpath. + 2006-09-18 Tom Tromey <tromey@redhat.com> * configure: Rebuilt. diff --git a/libjava/java/util/logging/LogManager.java b/libjava/java/util/logging/LogManager.java index 1c42069..b8b31c4 100644 --- a/libjava/java/util/logging/LogManager.java +++ b/libjava/java/util/logging/LogManager.java @@ -39,6 +39,8 @@ exception statement from your version. */ package java.util.logging; +import gnu.classpath.SystemProperties; + import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.ByteArrayInputStream; @@ -50,12 +52,11 @@ import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; -import gnu.classpath.SystemProperties; - /** * The <code>LogManager</code> maintains a hierarchical namespace * of Logger objects and manages properties for configuring the logging @@ -108,11 +109,23 @@ import gnu.classpath.SystemProperties; public class LogManager { /** + * The object name for the logging management bean. + * @since 1.5 + */ + public static final String LOGGING_MXBEAN_NAME + = "java.util.logging:type=Logging"; + + /** * The singleton LogManager instance. */ private static LogManager logManager; /** + * The singleton logging bean. + */ + private static LoggingMXBean loggingBean; + + /** * The registered named loggers; maps the name of a Logger to * a WeakReference to it. */ @@ -305,24 +318,21 @@ public class LogManager * When adding "foo.bar", the logger "foo.bar.baz" should change * its parent to "foo.bar". */ - if (parent != Logger.root) + for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();) { - for (Iterator iter = loggers.keySet().iterator(); iter.hasNext();) - { - Logger possChild = (Logger) ((WeakReference) loggers.get(iter.next())) - .get(); - if ((possChild == null) || (possChild == logger) - || (possChild.getParent() != parent)) - continue; - - if (! possChild.getName().startsWith(name)) - continue; - - if (possChild.getName().charAt(name.length()) != '.') - continue; - - possChild.setParent(logger); - } + Logger possChild = (Logger) ((WeakReference) loggers.get(iter.next())) + .get(); + if ((possChild == null) || (possChild == logger) + || (possChild.getParent() != parent)) + continue; + + if (! possChild.getName().startsWith(name)) + continue; + + if (possChild.getName().charAt(name.length()) != '.') + continue; + + possChild.setParent(logger); } return true; @@ -836,11 +846,11 @@ public class LogManager } catch (ClassNotFoundException e) { - warn(property, className, "class not found"); + warn(property, className, "class not found", e); } catch (IllegalAccessException e) { - warn(property, className, "illegal access"); + warn(property, className, "illegal access", e); } catch (InstantiationException e) { @@ -848,7 +858,7 @@ public class LogManager } catch (java.lang.LinkageError e) { - warn(property, className, "linkage error"); + warn(property, className, "linkage error", e); } return null; @@ -909,4 +919,63 @@ public class LogManager } } + /** + * Return the logging bean. There is a single logging bean per + * VM instance. + * @since 1.5 + */ + public static synchronized LoggingMXBean getLoggingMXBean() + { + if (loggingBean == null) + { + loggingBean = new LoggingMXBean() + { + public String getLoggerLevel(String logger) + { + LogManager mgr = getLogManager(); + Logger l = mgr.getLogger(logger); + if (l == null) + return null; + Level lev = l.getLevel(); + if (lev == null) + return ""; + return lev.getName(); + } + + public List getLoggerNames() + { + LogManager mgr = getLogManager(); + // This is inefficient, but perhaps better for maintenance. + return Collections.list(mgr.getLoggerNames()); + } + + public String getParentLoggerName(String logger) + { + LogManager mgr = getLogManager(); + Logger l = mgr.getLogger(logger); + if (l == null) + return null; + l = l.getParent(); + if (l == null) + return ""; + return l.getName(); + } + + public void setLoggerLevel(String logger, String level) + { + LogManager mgr = getLogManager(); + Logger l = mgr.getLogger(logger); + if (l == null) + throw new IllegalArgumentException("no logger named " + logger); + Level newLevel; + if (level == null) + newLevel = null; + else + newLevel = Level.parse(level); + l.setLevel(newLevel); + } + }; + } + return loggingBean; + } } |