Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-01-12 04:39:24 -0500
committerGreg Wilkins2012-01-12 04:39:24 -0500
commit564cf7329c28f6f4e3293b12643083727f8d7aa4 (patch)
tree4c48e5baaabd30f7f3e2d1d1fb492b2395d6d462
parent08f4b79a666c2d28793f3b6ed96a4d082a462cdf (diff)
downloadorg.eclipse.jetty.project-564cf7329c28f6f4e3293b12643083727f8d7aa4.tar.gz
org.eclipse.jetty.project-564cf7329c28f6f4e3293b12643083727f8d7aa4.tar.xz
org.eclipse.jetty.project-564cf7329c28f6f4e3293b12643083727f8d7aa4.zip
365302: made map of loggers concurrent and shared in abstract
-rw-r--r--jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties4
-rw-r--r--jetty-jmx/src/main/config/etc/jetty-jmx.xml3
-rw-r--r--jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/LogMBean.java48
-rw-r--r--jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Log-mbean.properties8
-rw-r--r--jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Logger-mbean.properties3
-rw-r--r--jetty-monitor/src/main/resources/org/eclipse/jetty/monitor/jmx/ThreadMonitor-mbean.properties1
-rw-r--r--jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties1
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/AbstractLogger.java59
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java9
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java20
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java9
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java9
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java100
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java8
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java19
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java6
16 files changed, 186 insertions, 121 deletions
diff --git a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties
index 4149820d53..f640c90a57 100644
--- a/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties
+++ b/jetty-deploy/src/main/resources/org/eclipse/jetty/deploy/jmx/DeploymentManager-mbean.properties
@@ -5,6 +5,6 @@ contexts:MMBean: Deployed Contexts
appProviders:MMBean: Application Providers
getApps(java.lang.String):MBean:ACTION: List apps that are located at specified App LifeCycle node
getApps(java.lang.String)[0]:nodeName: Name of the App LifeCycle node
-requestAppGoal(java.lang.String,java.lang.String) ACTION: Request the app to be moved to the specified App LifeCycle node
+requestAppGoal(java.lang.String,java.lang.String):ACTION: Request the app to be moved to the specified App LifeCycle node
requestAppGoal(java.lang.String,java.lang.String)[0]:appId:App identifier
-requestAppGoal(java.lang.String,java.lang.String)[1]:nodeName:Name of the App LifeCycle node \ No newline at end of file
+requestAppGoal(java.lang.String,java.lang.String)[1]:nodeName:Name of the App LifeCycle node
diff --git a/jetty-jmx/src/main/config/etc/jetty-jmx.xml b/jetty-jmx/src/main/config/etc/jetty-jmx.xml
index 7712cc512e..a685eded05 100644
--- a/jetty-jmx/src/main/config/etc/jetty-jmx.xml
+++ b/jetty-jmx/src/main/config/etc/jetty-jmx.xml
@@ -48,11 +48,10 @@
</Call>
<!-- Add the static log -->
- <Get id="Logger" class="org.eclipse.jetty.util.log.Log" name="log" />
<Ref id="MBeanContainer">
<Call name="addBean">
<Arg>
- <Ref id="Logger" />
+ <New class="org.eclipse.jetty.util.log.Log"/>
</Arg>
</Call>
</Ref>
diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/LogMBean.java b/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/LogMBean.java
new file mode 100644
index 0000000000..b5fa44b9c8
--- /dev/null
+++ b/jetty-jmx/src/main/java/org/eclipse/jetty/util/log/jmx/LogMBean.java
@@ -0,0 +1,48 @@
+// ========================================================================
+// Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+
+package org.eclipse.jetty.util.log.jmx;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jetty.jmx.ObjectMBean;
+import org.eclipse.jetty.util.log.Log;
+
+/* ------------------------------------------------------------ */
+/**
+ */
+public class LogMBean extends ObjectMBean
+{
+
+ public LogMBean(Object managedObject)
+ {
+ super(managedObject);
+ }
+
+ public List<String> getLoggers()
+ {
+ List<String> keySet = new ArrayList<String>(Log.getLoggers().keySet());
+ return keySet;
+ }
+
+ public boolean isDebugEnabled(String logger)
+ {
+ return Log.getLogger(logger).isDebugEnabled();
+ }
+
+ public void setDebugEnabled(String logger, Boolean enabled)
+ {
+ Log.getLogger(logger).setDebugEnabled(enabled);
+ }
+}
diff --git a/jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Log-mbean.properties b/jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Log-mbean.properties
new file mode 100644
index 0000000000..18abcb11ff
--- /dev/null
+++ b/jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Log-mbean.properties
@@ -0,0 +1,8 @@
+Log: Jetty Logging implementaton
+loggers:MBean: List of all instantiated loggers
+debugEnabled:RW: True if debug enabled for root logger Log.LOG
+isDebugEnabled(java.lang.String):MBean:INFO: True if debug is enabled for the given logger
+isDebugEnabled(java.lang.String)[0]:loggerName: Name of the logger to return isDebugEnabled for
+setDebugEnabled(java.lang.String,java.lang.Boolean):MBean:ACTION: Set debug enabled for the given logger
+setDebugEnabled(java.lang.String,java.lang.Boolean)[0]:loggerName: Name of the logger to set debug enabled
+setDebugEnabled(java.lang.String,java.lang.Boolean)[1]:enabled: true to enable debug, false otherwise
diff --git a/jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Logger-mbean.properties b/jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Logger-mbean.properties
deleted file mode 100644
index 416e992e5f..0000000000
--- a/jetty-jmx/src/main/resources/org/eclipse/jetty/util/log/jmx/Logger-mbean.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-Logger: Jetty Logging implementaton
-debugEnabled: True if debug enabled
-name: Logger name
diff --git a/jetty-monitor/src/main/resources/org/eclipse/jetty/monitor/jmx/ThreadMonitor-mbean.properties b/jetty-monitor/src/main/resources/org/eclipse/jetty/monitor/jmx/ThreadMonitor-mbean.properties
index 4bdb898173..c6f5a04f2c 100644
--- a/jetty-monitor/src/main/resources/org/eclipse/jetty/monitor/jmx/ThreadMonitor-mbean.properties
+++ b/jetty-monitor/src/main/resources/org/eclipse/jetty/monitor/jmx/ThreadMonitor-mbean.properties
@@ -1,2 +1 @@
ThreadMonitor: Detect and report spinning and deadlocked threads
-
diff --git a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties
index e45e145b39..7730ff4073 100644
--- a/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties
+++ b/jetty-servlet/src/main/resources/org/eclipse/jetty/servlet/jmx/Holder-mbean.properties
@@ -3,4 +3,3 @@ name: RO:Name
displayName: RO:Display Name
className: RO:Class Name
initParameters: RO:Initial parameters
-
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/AbstractLogger.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/AbstractLogger.java
new file mode 100644
index 0000000000..1320a9fc42
--- /dev/null
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/AbstractLogger.java
@@ -0,0 +1,59 @@
+package org.eclipse.jetty.util.log;
+
+
+/* ------------------------------------------------------------ */
+/** Abstract Logger.
+ * Manages the atomic registration of the logger by name.
+ */
+public abstract class AbstractLogger implements Logger
+{
+ public final Logger getLogger(String name)
+ {
+ if (isBlank(name))
+ return this;
+
+ final String basename = getName();
+ final String fullname = (isBlank(basename) || Log.getRootLogger()==this)?name:(basename + "." + name);
+
+ Logger logger = Log.getLoggers().get(fullname);
+ if (logger == null)
+ {
+ Logger newlog = newLogger(fullname);
+
+ logger = Log.getMutableLoggers().putIfAbsent(fullname,newlog);
+ if (logger == null)
+ logger=newlog;
+ }
+
+ return logger;
+ }
+
+
+ protected abstract Logger newLogger(String fullname);
+
+ /**
+ * A more robust form of name blank test. Will return true for null names, and names that have only whitespace
+ *
+ * @param name
+ * the name to test
+ * @return true for null or blank name, false if any non-whitespace character is found.
+ */
+ private static boolean isBlank(String name)
+ {
+ if (name == null)
+ {
+ return true;
+ }
+ int size = name.length();
+ char c;
+ for (int i = 0; i < size; i++)
+ {
+ c = name.charAt(i);
+ if (!Character.isWhitespace(c))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java
index 789bbf7751..dd8995caa4 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/JavaUtilLog.java
@@ -28,7 +28,7 @@ import java.util.logging.Level;
* standard java.util.logging configuration</a>.
* </p>
*/
-public class JavaUtilLog implements Logger
+public class JavaUtilLog extends AbstractLogger
{
private Level configuredLevel;
private java.util.logging.Logger _logger;
@@ -116,9 +116,12 @@ public class JavaUtilLog implements Logger
_logger.log(Level.FINE, msg, thrown);
}
- public Logger getLogger(String name)
+ /**
+ * Create a Child Logger of this Logger.
+ */
+ protected Logger newLogger(String fullname)
{
- return new JavaUtilLog(name);
+ return new JavaUtilLog(fullname);
}
public void ignore(Throwable ignored)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
index f6ce23a42e..30c6bb8d30 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Log.java
@@ -19,10 +19,14 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Loader;
@@ -61,7 +65,11 @@ public class Log
*/
public static boolean __ignored;
- public static Map<String, Logger> __loggers = new HashMap<String, Logger>();
+ /**
+ * Hold loggers only.
+ */
+ private final static ConcurrentMap<String, Logger> __loggers = new ConcurrentHashMap<String, Logger>();
+
static
{
@@ -427,14 +435,16 @@ public class Log
Logger logger = __loggers.get(name);
if(logger==null)
- {
logger = LOG.getLogger(name);
- __loggers.put(name,logger);
- }
return logger;
}
+ static ConcurrentMap<String, Logger> getMutableLoggers()
+ {
+ return __loggers;
+ }
+
/**
* Get a map of all configured {@link Logger} instances.
*
@@ -442,6 +452,6 @@ public class Log
*/
public static Map<String, Logger> getLoggers()
{
- return __loggers;
+ return Collections.unmodifiableMap(__loggers);
}
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java
index 3c2dc5f282..24eb559768 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/LoggerLog.java
@@ -18,7 +18,7 @@ import java.lang.reflect.Method;
/**
*
*/
-public class LoggerLog implements Logger
+public class LoggerLog extends AbstractLogger
{
private final Object _logger;
private final Method _debugMT;
@@ -189,11 +189,14 @@ public class LoggerLog implements Logger
}
}
- public Logger getLogger(String name)
+ /**
+ * Create a Child Logger of this Logger.
+ */
+ protected Logger newLogger(String fullname)
{
try
{
- Object logger=_getLoggerN.invoke(_logger, name);
+ Object logger=_getLoggerN.invoke(_logger, fullname);
return new LoggerLog(logger);
}
catch (Exception e)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java
index 2b8e268d1a..2dca95127f 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/Slf4jLog.java
@@ -18,7 +18,7 @@ package org.eclipse.jetty.util.log;
/**
* Slf4jLog Logger
*/
-public class Slf4jLog implements Logger
+public class Slf4jLog extends AbstractLogger
{
private final org.slf4j.Logger _logger;
@@ -114,9 +114,12 @@ public class Slf4jLog implements Logger
warn("setDebugEnabled not implemented",null,null);
}
- public Logger getLogger(String name)
+ /**
+ * Create a Child Logger of this Logger.
+ */
+ protected Logger newLogger(String fullname)
{
- return new Slf4jLog(name);
+ return new Slf4jLog(fullname);
}
public void ignore(Throwable ignored)
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
index 72192728e0..c0a2e246ee 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
@@ -35,7 +35,7 @@ import org.eclipse.jetty.util.DateCache;
* used for logging. For named debuggers, the system property name+".LONG" is checked. If it is not not set, then
* "org.eclipse.jetty.util.log.LONG" is used as the default.
*/
-public class StdErrLog implements Logger
+public class StdErrLog extends AbstractLogger
{
private static final String EOL = System.getProperty("line.separator");
private static DateCache _dateCache;
@@ -45,11 +45,6 @@ public class StdErrLog implements Logger
Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.SOURCE","false")));
private final static boolean __long = Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.stderr.LONG","false"));
- /**
- * Tracking for child loggers only.
- */
- private final static ConcurrentMap<String, StdErrLog> __loggers = new ConcurrentHashMap<String, StdErrLog>();
-
static
{
String deprecatedProperties[] =
@@ -332,28 +327,22 @@ public class StdErrLog implements Logger
{
if (enabled)
{
- synchronized (__loggers)
- {
- this._level = LEVEL_DEBUG;
+ this._level = LEVEL_DEBUG;
- // Boot stomp all cached log levels to DEBUG
- for(StdErrLog log: __loggers.values())
- {
- log._level = LEVEL_DEBUG;
- }
+ for (Logger log : Log.getLoggers().values())
+ {
+ if (log instanceof StdErrLog)
+ ((StdErrLog)log).setLevel(LEVEL_DEBUG);
}
}
else
{
- synchronized (__loggers)
+ this._level = this._configuredLevel;
+
+ for (Logger log : Log.getLoggers().values())
{
- this._level = this._configuredLevel;
-
- // restore all cached log configured levels
- for(StdErrLog log: __loggers.values())
- {
- log._level = log._configuredLevel;
- }
+ if (log instanceof StdErrLog)
+ ((StdErrLog)log).setLevel(((StdErrLog)log)._configuredLevel);
}
}
}
@@ -570,67 +559,18 @@ public class StdErrLog implements Logger
}
}
- /**
- * A more robust form of name blank test. Will return true for null names, and names that have only whitespace
- *
- * @param name
- * the name to test
- * @return true for null or blank name, false if any non-whitespace character is found.
- */
- private static boolean isBlank(String name)
- {
- if (name == null)
- {
- return true;
- }
- int size = name.length();
- char c;
- for (int i = 0; i < size; i++)
- {
- c = name.charAt(i);
- if (!Character.isWhitespace(c))
- {
- return false;
- }
- }
- return true;
- }
/**
- * Get a Child Logger relative to this Logger.
- *
- * @param name
- * the child name
- * @return the appropriate child logger (if name specified results in a new unique child)
+ * Create a Child Logger of this Logger.
*/
- public Logger getLogger(String name)
- {
- if (isBlank(name))
- {
- return this;
- }
-
- String fullname = name;
- if (!isBlank(_name))
- {
- fullname = _name + "." + name;
- }
-
- StdErrLog logger = __loggers.get(fullname);
- if (logger == null)
- {
- StdErrLog sel = new StdErrLog(fullname);
- // Preserve configuration for new loggers configuration
- sel.setPrintLongNames(_printLongNames);
- // Let Level come from configured Properties instead - sel.setLevel(_level);
- sel.setSource(_source);
- sel._stderr = this._stderr;
- logger = __loggers.putIfAbsent(fullname,sel);
- if (logger == null)
- {
- logger = sel;
- }
- }
+ protected Logger newLogger(String fullname)
+ {
+ StdErrLog logger = new StdErrLog(fullname);
+ // Preserve configuration for new loggers configuration
+ logger.setPrintLongNames(_printLongNames);
+ // Let Level come from configured Properties instead - sel.setLevel(_level);
+ logger.setSource(_source);
+ logger._stderr = this._stderr;
return logger;
}
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java
index e5322ca63b..d371a13a45 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/LogTest.java
@@ -15,6 +15,9 @@ package org.eclipse.jetty.util.log;
import static org.hamcrest.Matchers.is;
+import java.util.HashMap;
+import java.util.Map;
+
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -23,18 +26,23 @@ import org.junit.Test;
public class LogTest
{
private static Logger originalLogger;
+ private static Map<String,Logger> originalLoggers;
@SuppressWarnings("deprecation")
@BeforeClass
public static void rememberOriginalLogger()
{
originalLogger = Log.getLog();
+ originalLoggers = new HashMap<String, Logger>(Log.getLoggers());
+ Log.getMutableLoggers().clear();
}
@AfterClass
public static void restoreOriginalLogger()
{
Log.setLog(originalLogger);
+ Log.getMutableLoggers().clear();
+ Log.getMutableLoggers().putAll(originalLoggers);
}
@Test
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java
index dc1a86e84a..4377d5feaf 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/NamedLogTest.java
@@ -1,26 +1,9 @@
package org.eclipse.jetty.util.log;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
import org.junit.Test;
public class NamedLogTest
{
- private static Logger originalLogger;
-
- @SuppressWarnings("deprecation")
- @BeforeClass
- public static void rememberOriginalLogger()
- {
- originalLogger = Log.getLog();
- }
-
- @AfterClass
- public static void restoreOriginalLogger()
- {
- Log.setLog(originalLogger);
- }
-
@Test
public void testNamedLogging()
{
@@ -37,7 +20,7 @@ public class NamedLogTest
red.generateLogs();
green.generateLogs();
blue.generateLogs();
-
+
output.assertContains(Red.class.getName());
output.assertContains(Green.class.getName());
output.assertContains(Blue.class.getName());
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java
index b9b536db80..cd55fc125a 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrCapture.java
@@ -43,4 +43,10 @@ public class StdErrCapture
String output = new String(test.toByteArray());
Assert.assertThat(output,not(containsString(unexpectedString)));
}
+
+ public String toString()
+ {
+ err.flush();
+ return new String(test.toByteArray());
+ }
}

Back to the top