From 55a650f08cd7afee64689a758942104c88458c85 Mon Sep 17 00:00:00 2001 From: Ceki Gulcu Date: Sat, 4 Nov 2006 18:35:32 +0000 Subject: [PATCH] - Fixed synchronisation related bug number 27. See also http://bugzilla.slf4j.org/show_bug.cgi?id=27 - added eclipse codeStyle.xml - The various SLF4J inherit their version number through a poperty, namely "aversion", defined in the parent pom. This little trick seems to work well and saves alot of time. --- codeStyle.xml | 251 ++++++++++++++++++ jcl104-over-slf4j/pom.xml | 7 +- .../commons/logging/impl/SLF4FLogFactory.java | 45 ++-- log4j-over-slf4j/pom.xml | 4 +- .../org/apache/log4j/Log4jLoggerFactory.java | 22 +- pom.xml | 34 ++- slf4j-api/pom.xml | 5 +- slf4j-archetype/pom.xml | 4 +- slf4j-jcl/pom.xml | 4 +- .../java/org/slf4j/impl/JCLLoggerFactory.java | 24 +- slf4j-jdk14/pom.xml | 5 +- .../org/slf4j/impl/JDK14LoggerFactory.java | 27 +- slf4j-log4j12/pom.xml | 4 +- .../org/slf4j/impl/Log4jLoggerFactory.java | 24 +- slf4j-nop/pom.xml | 4 +- slf4j-simple/pom.xml | 4 +- .../org/slf4j/impl/SimpleLoggerFactory.java | 35 +-- slf4j-site/pom.xml | 4 +- slf4j-site/src/site/xdocs/news.xml | 26 +- slf4j-skin/pom.xml | 4 +- updateBundle.sh | 2 +- 21 files changed, 425 insertions(+), 114 deletions(-) create mode 100644 codeStyle.xml diff --git a/codeStyle.xml b/codeStyle.xml new file mode 100644 index 00000000..21b42b61 --- /dev/null +++ b/codeStyle.xml @@ -0,0 +1,251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jcl104-over-slf4j/pom.xml b/jcl104-over-slf4j/pom.xml index 21e262dd..8aeb63df 100644 --- a/jcl104-over-slf4j/pom.xml +++ b/jcl104-over-slf4j/pom.xml @@ -3,14 +3,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j jcl104-over-slf4j - ${parent.version} + ${aversion} jar JCL Implemented Over SLF4J @@ -26,9 +26,6 @@ ${project.version} provided - - - \ No newline at end of file diff --git a/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4FLogFactory.java b/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4FLogFactory.java index 77a3c559..137b6306 100644 --- a/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4FLogFactory.java +++ b/jcl104-over-slf4j/src/main/java/org/apache/commons/logging/impl/SLF4FLogFactory.java @@ -31,15 +31,15 @@ import org.slf4j.LoggerFactory; /** *

* Concrete subclass of {@link LogFactory} which always delegates to the - * {@link LoggerFactory org.slf4j.LoggerFactory} class. + * {@link LoggerFactory org.slf4j.LoggerFactory} class. * *

- * This factory generates instances of {@link SLF4JLog}. It will remember - * previously created instances for the same name, and will - * return them on repeated requests to the - * getInstance() method. + * This factory generates instances of {@link SLF4JLog}. It will remember + * previously created instances for the same name, and will return them on + * repeated requests to the getInstance() method. * - *

This implementation ignores any configured attributes. + *

+ * This implementation ignores any configured attributes. *

* * @author Rod Waldhoff @@ -146,12 +146,15 @@ public class SLF4FLogFactory extends LogFactory { * if a suitable Log instance cannot be returned */ public Log getInstance(String name) throws LogConfigurationException { - - Log instance = (Log) loggerMap.get(name); - if (instance == null) { - Logger logger = LoggerFactory.getLogger(name); - instance = new SLF4JLog(logger); - loggerMap.put(name, instance); + Log instance = null; + // protect against concurrent access of loggerMap + synchronized (this) { + instance = (Log) loggerMap.get(name); + if (instance == null) { + Logger logger = LoggerFactory.getLogger(name); + instance = new SLF4JLog(logger); + loggerMap.put(name, instance); + } } return (instance); @@ -166,15 +169,19 @@ public class SLF4FLogFactory extends LogFactory { */ public void release() { // This method is never called by jcl-over-slf4j classes. However, - // in certain deployment scenarios, in particular if jcl104-over-slf4j.jar is + // in certain deployment scenarios, in particular if jcl104-over-slf4j.jar + // is // in the the web-app class loader and the official commons-logging.jar is - // deployed in some parent class loader (e.g. commons/lib), then it is possible - // for the parent class loader to mask the classes shipping in + // deployed in some parent class loader (e.g. commons/lib), then it is + // possible + // for the parent class loader to mask the classes shipping in // jcl104-over-slf4j.jar. - System.out.println("WARN: The method "+SLF4FLogFactory.class+"#release() was invoked."); - System.out.println("WARN: Please see http://www.slf4j.org/codes.html for an explanation."); - System.out.flush(); - } + System.out.println("WARN: The method " + SLF4FLogFactory.class + + "#release() was invoked."); + System.out + .println("WARN: Please see http://www.slf4j.org/codes.html for an explanation."); + System.out.flush(); + } /** * Remove any configuration attribute associated with the specified name. If diff --git a/log4j-over-slf4j/pom.xml b/log4j-over-slf4j/pom.xml index deadf146..ceee2c34 100644 --- a/log4j-over-slf4j/pom.xml +++ b/log4j-over-slf4j/pom.xml @@ -3,14 +3,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j log4j-over-slf4j - ${parent.version} + ${aversion} jar Log4j Implemented Over SLF4J diff --git a/log4j-over-slf4j/src/main/java/org/apache/log4j/Log4jLoggerFactory.java b/log4j-over-slf4j/src/main/java/org/apache/log4j/Log4jLoggerFactory.java index 71922743..94484c23 100644 --- a/log4j-over-slf4j/src/main/java/org/apache/log4j/Log4jLoggerFactory.java +++ b/log4j-over-slf4j/src/main/java/org/apache/log4j/Log4jLoggerFactory.java @@ -12,7 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.apache.log4j; @@ -29,16 +29,16 @@ import java.util.Hashtable; */ public class Log4jLoggerFactory { - private static Hashtable log4jLoggers = new Hashtable(); + private static Hashtable log4jLoggers = new Hashtable(); - public static Logger getLogger(String name) { - if (log4jLoggers.containsKey(name)) { - return (org.apache.log4j.Logger) log4jLoggers.get(name); - } else { - Logger log4jLogger = new Logger(name); - log4jLoggers.put(name, log4jLogger); - return log4jLogger; - } - } + public static synchronized Logger getLogger(String name) { + if (log4jLoggers.containsKey(name)) { + return (org.apache.log4j.Logger) log4jLoggers.get(name); + } else { + Logger log4jLogger = new Logger(name); + log4jLoggers.put(name, log4jLogger); + return log4jLogger; + } + } } diff --git a/pom.xml b/pom.xml index 7060b035..82b8f456 100644 --- a/pom.xml +++ b/pom.xml @@ -5,14 +5,17 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT pom SLF4J - http://www.slf4j.org + + 1.1.0-RC0 + + QOS.ch http://www.qos.ch @@ -41,6 +44,8 @@ test + + @@ -118,6 +123,15 @@ + + + skipTests + + true + + + + @@ -135,14 +149,14 @@ - maven-assembly-plugin - 2.1 - - - - src/main/assembly/source.xml - - + maven-assembly-plugin + 2.1 + + + + src/main/assembly/source.xml + + slf4j-${project.version} false target/site/dist/ diff --git a/slf4j-api/pom.xml b/slf4j-api/pom.xml index 706b8ca9..2432f143 100644 --- a/slf4j-api/pom.xml +++ b/slf4j-api/pom.xml @@ -6,14 +6,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-api - ${parent.version} + ${aversion} jar SLF4J API Module @@ -26,7 +26,6 @@ - diff --git a/slf4j-archetype/pom.xml b/slf4j-archetype/pom.xml index 537d4b85..b40fe928 100644 --- a/slf4j-archetype/pom.xml +++ b/slf4j-archetype/pom.xml @@ -2,7 +2,7 @@ slf4j-parent org.slf4j - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 @@ -10,7 +10,7 @@ slf4j-archetype Archetype - slf4j-archetype jar - ${parent.version} + ${aversion} http://www.slf4j.org diff --git a/slf4j-jcl/pom.xml b/slf4j-jcl/pom.xml index 0d71bff4..743ff09c 100644 --- a/slf4j-jcl/pom.xml +++ b/slf4j-jcl/pom.xml @@ -3,14 +3,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-jcl - ${parent.version} + ${aversion} jar SLF4J JCL Binding diff --git a/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerFactory.java b/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerFactory.java index efab074b..e955b53d 100644 --- a/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerFactory.java +++ b/slf4j-jcl/src/main/java/org/slf4j/impl/JCLLoggerFactory.java @@ -41,9 +41,9 @@ import org.slf4j.ILoggerFactory; import org.slf4j.Logger; /** - * JCLLoggerFactory is an implementation of {@link ILoggerFactory} - * returning the appropriately named {@link JCLLoggerAdapter} instance. - * + * JCLLoggerFactory is an implementation of {@link ILoggerFactory} returning the + * appropriately named {@link JCLLoggerAdapter} instance. + * * @author Ceki Gülcü */ public class JCLLoggerFactory implements ILoggerFactory { @@ -55,15 +55,21 @@ public class JCLLoggerFactory implements ILoggerFactory { loggerMap = new HashMap(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.slf4j.ILoggerFactory#getLogger(java.lang.String) */ public Logger getLogger(String name) { - Logger logger = (Logger) loggerMap.get(name); - if (logger == null) { - org.apache.commons.logging.Log jclLogger = LogFactory.getLog(name); - logger = new JCLLoggerAdapter(jclLogger, name); - loggerMap.put(name, logger); + Logger logger = null; + // protect against concurrent access of loggerMap + synchronized (this) { + logger = (Logger) loggerMap.get(name); + if (logger == null) { + org.apache.commons.logging.Log jclLogger = LogFactory.getLog(name); + logger = new JCLLoggerAdapter(jclLogger, name); + loggerMap.put(name, logger); + } } return logger; } diff --git a/slf4j-jdk14/pom.xml b/slf4j-jdk14/pom.xml index 44d04b16..dde7e974 100644 --- a/slf4j-jdk14/pom.xml +++ b/slf4j-jdk14/pom.xml @@ -6,14 +6,15 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-jdk14 - ${parent.version} + ${aversion} + jar SLF4J JDK14 Binding diff --git a/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java b/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java index 3c9ae4eb..f4367630 100644 --- a/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java +++ b/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java @@ -40,9 +40,9 @@ import java.util.HashMap; import java.util.Map; /** - * JDK14LoggerFactory is an implementation of {@link ILoggerFactory} - * returning the appropriately named {@link JDK14LoggerAdapter} instance. - * + * JDK14LoggerFactory is an implementation of {@link ILoggerFactory} returning + * the appropriately named {@link JDK14LoggerAdapter} instance. + * * @author Ceki Gülcü */ public class JDK14LoggerFactory implements ILoggerFactory { @@ -54,15 +54,22 @@ public class JDK14LoggerFactory implements ILoggerFactory { loggerMap = new HashMap(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.slf4j.ILoggerFactory#getLogger(java.lang.String) */ - public Logger getLogger(String name) { - Logger ulogger = (Logger) loggerMap.get(name); - if (ulogger == null) { - java.util.logging.Logger logger = java.util.logging.Logger.getLogger(name); - ulogger = new JDK14LoggerAdapter(logger); - loggerMap.put(name, ulogger); + public synchronized Logger getLogger(String name) { + Logger ulogger = null; + // protect against concurrent access of loggerMap + synchronized (this) { + ulogger = (Logger) loggerMap.get(name); + if (ulogger == null) { + java.util.logging.Logger logger = java.util.logging.Logger + .getLogger(name); + ulogger = new JDK14LoggerAdapter(logger); + loggerMap.put(name, ulogger); + } } return ulogger; } diff --git a/slf4j-log4j12/pom.xml b/slf4j-log4j12/pom.xml index 969a3994..48fe3198 100644 --- a/slf4j-log4j12/pom.xml +++ b/slf4j-log4j12/pom.xml @@ -6,14 +6,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-log4j12 - ${parent.version} + ${aversion} jar SLF4J LOG4J-12 Binding diff --git a/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java b/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java index f254e726..20e48cfe 100644 --- a/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java +++ b/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java @@ -41,9 +41,9 @@ import org.slf4j.ILoggerFactory; import org.slf4j.Logger; /** - * Log4jLoggerFactory is an implementation of {@link ILoggerFactory} - * returning the appropriate named {@link Log4jLoggerAdapter} instance. - * + * Log4jLoggerFactory is an implementation of {@link ILoggerFactory} returning + * the appropriate named {@link Log4jLoggerAdapter} instance. + * * @author Ceki Gülcü */ public class Log4jLoggerFactory implements ILoggerFactory { @@ -55,15 +55,21 @@ public class Log4jLoggerFactory implements ILoggerFactory { loggerMap = new HashMap(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.slf4j.ILoggerFactory#getLogger(java.lang.String) */ public Logger getLogger(String name) { - Logger slf4jLogger = (Logger) loggerMap.get(name); - if (slf4jLogger == null) { - org.apache.log4j.Logger logger = LogManager.getLogger(name); - slf4jLogger = new Log4jLoggerAdapter(logger); - loggerMap.put(name, slf4jLogger); + Logger slf4jLogger = null; + // protect against concurrent access of loggerMap + synchronized (this) { + slf4jLogger = (Logger) loggerMap.get(name); + if (slf4jLogger == null) { + org.apache.log4j.Logger logger = LogManager.getLogger(name); + slf4jLogger = new Log4jLoggerAdapter(logger); + loggerMap.put(name, slf4jLogger); + } } return slf4jLogger; } diff --git a/slf4j-nop/pom.xml b/slf4j-nop/pom.xml index 65b3f88f..b2348e5d 100644 --- a/slf4j-nop/pom.xml +++ b/slf4j-nop/pom.xml @@ -6,14 +6,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-nop - ${parent.version} + ${aversion} jar SLF4J NOP Binding diff --git a/slf4j-simple/pom.xml b/slf4j-simple/pom.xml index ee1e05e1..e547c38a 100644 --- a/slf4j-simple/pom.xml +++ b/slf4j-simple/pom.xml @@ -3,14 +3,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-simple - ${parent.version} + ${aversion} jar SLF4J Simple Binding diff --git a/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java b/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java index 146476f0..95df0123 100644 --- a/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java +++ b/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java @@ -39,7 +39,6 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.ILoggerFactory; - /** * An implementation of {@link ILoggerFactory} which always returns * {@link SimpleLogger} instances. @@ -48,31 +47,33 @@ import org.slf4j.ILoggerFactory; */ public class SimpleLoggerFactory implements ILoggerFactory { - /** - * A default instance of SimpleLoggerFactory. This default instance may be used - * to retrieve a simple logger as a last-resort fallback logger. This instance - * is designed to be used by a very specific group of users, namely for those - * developing fully-fledged logging systems (e.g. log4j or logback). It is not - * intended for end-users of the SLF4J API. + * A default instance of SimpleLoggerFactory. This default instance may be + * used to retrieve a simple logger as a last-resort fallback logger. This + * instance is designed to be used by a very specific group of users, namely + * for those developing fully-fledged logging systems (e.g. log4j or logback). + * It is not intended for end-users of the SLF4J API. */ public final static SimpleLoggerFactory INSTANCE = new SimpleLoggerFactory(); - - Map map; - + + Map loggerMap; + public SimpleLoggerFactory() { - map = new HashMap(); + loggerMap = new HashMap(); } - /** - * Return an appropriate {@link SimpleLogger} instance by name. + * Return an appropriate {@link SimpleLogger} instance by name. */ public Logger getLogger(String name) { - Logger slogger = (Logger) map.get(name); - if(slogger == null) { - slogger = new SimpleLogger(name); - map.put(name, slogger); + Logger slogger = null; + // protect against concurrent access of the loggerMap + synchronized (this) { + slogger = (Logger) loggerMap.get(name); + if (slogger == null) { + slogger = new SimpleLogger(name); + loggerMap.put(name, slogger); + } } return slogger; } diff --git a/slf4j-site/pom.xml b/slf4j-site/pom.xml index d631af54..a3ce3518 100644 --- a/slf4j-site/pom.xml +++ b/slf4j-site/pom.xml @@ -5,14 +5,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-site - ${parent.version} + ${aversion} pom SLF4J Site diff --git a/slf4j-site/src/site/xdocs/news.xml b/slf4j-site/src/site/xdocs/news.xml index 7d2fc5d4..5acce369 100644 --- a/slf4j-site/src/site/xdocs/news.xml +++ b/slf4j-site/src/site/xdocs/news.xml @@ -17,9 +17,31 @@
-

September 7th, 2006 - Release of SLF4J 1.1.0-RC1

+

November 4th, 2006 - Release of SLF4J 1.1.0-RC0

-

Release 1.1.0-RC1 is a relatively important release with a +

Given that release 1.1.0-beta0 consisted mainly of + packaging-related changes which seem to work well, this release is + marked as RC0.

+ +

Fixed the JDK 1.5 dependency for the SLF4J build, as reported by + Boris Unkel in bug number + 28. SLF4J now explicitly declares a dependency on JDK 1.4 in + its pom.xml file. +

+ +

Fixed an incorrect reference to the logback project in slf4j-api + pom file. This bug was reported by Boris Unkel in bug number + 29. +

+ + +
+ +

September 7th, 2006 - Release of SLF4J 1.1.0-beta0

+ +

Release 1.1.0-beta0 is a relatively important release with a refactoring of the way class files are organized in jar files. In previous releases, each binding was self-contained in a single jar file. In this release, each and every binding depends on diff --git a/slf4j-skin/pom.xml b/slf4j-skin/pom.xml index f3a6874d..41303330 100644 --- a/slf4j-skin/pom.xml +++ b/slf4j-skin/pom.xml @@ -5,14 +5,14 @@ org.slf4j slf4j-parent - 1.1.0-beta0 + 1.0-SNAPSHOT 4.0.0 org.slf4j slf4j-skin - ${parent.version} + ${aversion} jar SLF4J Website Skin diff --git a/updateBundle.sh b/updateBundle.sh index 3dd2ef94..35afb330 100644 --- a/updateBundle.sh +++ b/updateBundle.sh @@ -1,5 +1,5 @@ -VERSION=1.1.0-beta0 +VERSION=1.1.0-RC0 echo $VERSION MVN=/java/maven-2.0.4/bin/mvn