[jboss-svn-commits] JBoss Common SVN: r3357 - jboss-logmanager/trunk/src/main/java/org/jboss/logmanager.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 9 01:44:28 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-07-09 01:44:28 -0400 (Thu, 09 Jul 2009)
New Revision: 3357
Modified:
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Configurator.java
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java
Log:
Attach the configurator on to the root logger so that configured loggers do not disappear during bootstrap
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Configurator.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Configurator.java 2009-07-09 05:16:08 UTC (rev 3356)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Configurator.java 2009-07-09 05:44:28 UTC (rev 3357)
@@ -37,4 +37,10 @@
* @throws IOException if an error occurs
*/
void configure(InputStream inputStream) throws IOException;
+
+ /**
+ * The attachment key of the chosen configurator, used to maintain a strong ref to any
+ * configured properties.
+ */
+ Logger.AttachmentKey<Configurator> ATTACHMENT_KEY = new Logger.AttachmentKey<Configurator>();
}
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java 2009-07-09 05:16:08 UTC (rev 3356)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/LogManager.java 2009-07-09 05:44:28 UTC (rev 3357)
@@ -226,6 +226,7 @@
final Configurator configurator = construct(Configurator.class, confClassName);
try {
configurator.configure(inputStream);
+ LogContext.getSystemLogContext().getLogger("").attach(Configurator.ATTACHMENT_KEY, configurator);
} catch (Throwable t) {
t.printStackTrace();
}
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java 2009-07-09 05:16:08 UTC (rev 3356)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/Logger.java 2009-07-09 05:44:28 UTC (rev 3357)
@@ -241,12 +241,47 @@
}
/**
+ * Attach an object to this logger under a given key.
+ * A strong reference is maintained to the key and value for as long as this logger exists.
+ *
+ * @param key the attachment key
+ * @param value the attachment value
+ * @param <V> the attachment value type
+ * @return the old attachment, if there was one
+ * @throws SecurityException if a security manager exists and if the caller does not have {@code LoggingPermission(control)}
+ */
+ @SuppressWarnings({ "unchecked" })
+ public <V> V attach(AttachmentKey<V> key, V value) throws SecurityException {
+ LogContext.checkAccess();
+ if (key == null) {
+ throw new NullPointerException("key is null");
+ }
+ if (value == null) {
+ throw new NullPointerException("value is null");
+ }
+ Map<AttachmentKey, Object> oldAttachments;
+ Map<AttachmentKey, Object> newAttachments;
+ V old;
+ do {
+ oldAttachments = attachments;
+ if (oldAttachments.isEmpty() || oldAttachments.size() == 1 && oldAttachments.containsKey(key)) {
+ old = (V) oldAttachments.get(key);
+ newAttachments = Collections.<AttachmentKey, Object>singletonMap(key, value);
+ } else {
+ newAttachments = new HashMap<AttachmentKey, Object>(oldAttachments);
+ old = (V) newAttachments.put(key, value);
+ }
+ } while (! attachmentsUpdater.compareAndSet(this, oldAttachments, newAttachments));
+ return old;
+ }
+
+ /**
* Attach an object to this logger under a given key, if such an attachment does not already exist.
* A strong reference is maintained to the key and value for as long as this logger exists.
*
* @param key the attachment key
+ * @param value the attachment value
* @param <V> the attachment value type
- * @param value the attachment value
* @return the current attachment, if there is one, or {@code null} if the value was successfully attached
* @throws SecurityException if a security manager exists and if the caller does not have {@code LoggingPermission(control)}
*/
@@ -798,4 +833,8 @@
*/
public static final class AttachmentKey<V> {
}
+
+ public String toString() {
+ return "Logger '" + getName() + "' in context " + loggerNode.getContext();
+ }
}
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java 2009-07-09 05:16:08 UTC (rev 3356)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java 2009-07-09 05:44:28 UTC (rev 3357)
@@ -61,6 +61,7 @@
private Map<String, Filter> configuredFilters;
private Map<String, Formatter> configuredFormatters;
private Map<String, ErrorManager> configuredErrorManagers;
+ private Map<String, Logger> configuredLoggers;
/** {@inheritDoc} */
public void configure(final InputStream inputStream) throws IOException {
@@ -68,6 +69,7 @@
configuredFilters = new HashMap<String, Filter>();
configuredFormatters = new HashMap<String, Formatter>();
configuredErrorManagers = new HashMap<String, ErrorManager>();
+ configuredLoggers = new HashMap<String, Logger>();
final Properties properties = new Properties();
try {
properties.load(inputStream);
@@ -90,6 +92,7 @@
continue;
}
final Logger logger = LogContext.getSystemLogContext().getLogger(loggerName);
+ configuredLoggers.put(loggerName, logger);
// Get logger level
final String levelName = getStringProperty(properties, getKey("logger", loggerName, "level"));
More information about the jboss-svn-commits
mailing list