Skip to content

Commit

Permalink
Given the huge size of the SLF4J user base, we need a more lenient ve…
Browse files Browse the repository at this point in the history
…rsion

check mechanism. For example, we can't expect external implementations such as
Mina, jetty, jboss to follow SLF4J's release schedule. We just can't.

This commit changes the version check policy to become elective. The FAQ includes an entry explaining 
the logic.
  • Loading branch information
ceki committed Oct 17, 2008
1 parent c7268f5 commit 2050a4d
Show file tree
Hide file tree
Showing 31 changed files with 198 additions and 143 deletions.
3 changes: 3 additions & 0 deletions binderVersion.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
}

$V= $ARGV[0];
# Trim -SNAPSHOT
$V =~ s/-SNAPSHOT//;

print "VER:${V}\r\n";
shift(@ARGV);

Expand Down
2 changes: 1 addition & 1 deletion goVersion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ echo "Changing pom.xml files"
find . -name "pom.xml" |xargs perl version.pl ${VER}
echo "Changing Java files"
find . -name "StaticLoggerBinder.java" |xargs perl binderVersion.pl ${VER}
find slf4j-api -name "LoggerFactory.java" |xargs perl binderVersion.pl ${VER}

6 changes: 3 additions & 3 deletions integration/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@
</target>

<target name="testAll" depends="init,
testPre154,
testPre155,
testMatch">
</target>

<target name="testPre154">
<target name="testPre155">
<junit printsummary="yes" fork="no" haltonfailure="yes">
<classpath refid="path150" />
<formatter type="plain" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.Pre154VersionMismatchTest" />
<test fork="yes" todir="target/unit-reports" name="org.slf4j.Pre155VersionMismatchTest" />
</junit>
</target>

Expand Down
2 changes: 1 addition & 1 deletion integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@

import junit.framework.TestCase;

public class Pre154VersionMismatchTest extends TestCase {
public class Pre155VersionMismatchTest extends TestCase {


StringPrintStream sps = new StringPrintStream(System.err);
PrintStream old = System.err;
int diff = 1024 + new Random().nextInt(10000);
public Pre154VersionMismatchTest(String name) {

public Pre155VersionMismatchTest(String name) {
super(name);
}

Expand All @@ -26,18 +25,11 @@ protected void tearDown() throws Exception {
System.setErr(old);
}


public void test() throws Exception {
public void test() throws Exception {
Logger logger = LoggerFactory.getLogger(this.getClass());
String msg = "hello world "+diff;
String msg = "hello world " + diff;
logger.info(msg);
String s0 = (String) sps.stringList.get(0);
assertTrue(s0.startsWith("SLF4J: The version of your slf4j-binding is probably older than 1.5.4"));

String s1 = (String) sps.stringList.get(1);
assertTrue(s1.contains(LoggerFactory.VERSION_MISMATCH));

String s2 = (String) sps.stringList.get(2);
assertTrue(s2.contains(msg));
assertTrue(s0.contains(msg));
}
}
2 changes: 1 addition & 1 deletion jcl-over-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion jcl104-over-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion jul-to-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion log4j-over-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion osgi-over-slf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>

<packaging>pom</packaging>
<name>SLF4J</name>
Expand Down
2 changes: 1 addition & 1 deletion slf4j-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
42 changes: 28 additions & 14 deletions slf4j-api/src/main/java/org/slf4j/LoggerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.slf4j.helpers.SubstituteLoggerFactory;
Expand Down Expand Up @@ -56,7 +57,13 @@ public final class LoggerFactory {
static final String VERSION_MISMATCH = "http://www.slf4j.org/codes.html#version_mismatch";
static final String SUBSTITUTE_LOGGER_URL = "http://www.slf4j.org/codes.html#substituteLogger";

static private final String EXPECTED_VERSION = "1.5.4";
/**
* It is out responsibility to track version changes and manage the
* compatibility list.
*
* <p>
*/
static private final String[] API_COMPATIBILITY_LIST = new String[] { "1.5.5" };

// private constructor prevents instantiation
private LoggerFactory() {
Expand Down Expand Up @@ -95,7 +102,7 @@ private final static void staticInitialize() {
}

private final static void emitSubstitureLoggerWarning(List loggerNameList) {
if(loggerNameList.size() == 0) {
if (loggerNameList.size() == 0) {
return;
}
Util
Expand All @@ -111,22 +118,29 @@ private final static void emitSubstitureLoggerWarning(List loggerNameList) {

private final static void versionSanityCheck() {
try {
String actualVer = StaticLoggerBinder.VERSION;
if (!EXPECTED_VERSION.equals(actualVer)) {
Util.reportFailure("The version " + actualVer
+ " of your slf4j-binding differs from " + EXPECTED_VERSION
+ ", the expected version.");
String requested = StaticLoggerBinder.REQUESTED_API_VERSION;

boolean match = false;
for (int i = 0; i < API_COMPATIBILITY_LIST.length; i++) {
if (API_COMPATIBILITY_LIST[i].equals(requested)) {
match = true;
}
}
if (!match) {
Util.reportFailure("The requested version " + requested
+ " of your slf4j-binding does not match any of "
+ Arrays.toString(API_COMPATIBILITY_LIST));
Util.reportFailure("See " + VERSION_MISMATCH + " for further details.");
}
} catch (java.lang.NoSuchFieldError nsfe) {
Util
.reportFailure("The version of your slf4j-binding is probably older than 1.5.4, and differs from "
+ EXPECTED_VERSION + ", the expected version.");
Util.reportFailure("See " + VERSION_MISMATCH + " for further details.");
// given our large user base anbd SLF4J's commitment to backward
// compatibility, we cannot cry
// here. Only for implementations which willingly declare a
// REQUESTED_API_VERSION field do we emit compatibility warnings.
} catch (Throwable e) {
Util
.reportFailure("An unexpected problem occured while checking the version of your slf4j-binding");
e.printStackTrace();
// we should never reach here
Util.reportFailure(
"Unexpected problem occured during version sanity check", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public class StaticLoggerBinder {
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

/**
* Version tag used to check compatibility. The value of this field is
* modified with each release.
* Declare the version of the SLF4J API this implementation is compiled against.
* The value of this field is usually modified with each release.
*/
// to avoid constant folding by the compiler, VERSION field should *not* be final
public static String VERSION = "1.5.4"; // !final
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.5.5"; // !final

private StaticLoggerBinder() {
throw new UnsupportedOperationException("This code should have never made it into the jar");
Expand Down
2 changes: 1 addition & 1 deletion slf4j-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion slf4j-jcl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
* Version tag used to check compatibility. The value of this field is
* modified with each release.
*/
//to avoid constant folding by the compiler, VERSION field should *not* be final
public static String VERSION = "1.5.4";

//to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.5.5";

// Binding specific code:
private static final String loggerFactoryClassStr = JCLLoggerFactory.class
Expand Down
2 changes: 1 addition & 1 deletion slf4j-jdk14/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
13 changes: 7 additions & 6 deletions slf4j-jdk14/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
* The unique instance of this class.
*/
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

/**
* Version tag used to check compatibility. The value of this field is
* modified with each release.
*/
//to avoid constant folding by the compiler, VERSION field should *not* be final
public static String VERSION = "1.5.4";
* Declare the version of the SLF4J API this implementation is compiled against.
* The value of this field is usually modified with each release.
*/
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.5.5"; // !final


private static final String loggerFactoryClassStr = org.slf4j.impl.JDK14LoggerFactory.class.getName();

Expand Down
2 changes: 1 addition & 1 deletion slf4j-log4j12/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

/**
* Version tag used to check compatibility. The value of this field is
* modified in each release.
* Declare the version of the SLF4J API this implementation is compiled against.
* The value of this field is usually modified with each release.
*/
public static final String VERSION = "1.5.4";
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.5.5"; // !final

private static final String loggerFactoryClassStr = Log4jLoggerFactory.class.getName();

Expand Down
2 changes: 1 addition & 1 deletion slf4j-migrator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion slf4j-nop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
10 changes: 5 additions & 5 deletions slf4j-nop/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

/**
* Version tag used to check compatibility. The value of this field is
* modified with each release.
*/
//to avoid constant folding by the compiler, VERSION field should *not* be final
public static String VERSION = "1.5.4";
* Declare the version of the SLF4J API this implementation is compiled against.
* The value of this field is usually modified with each release.
*/
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.5.5"; // !final

private static final String loggerFactoryClassStr = NOPLoggerFactory.class.getName();

Expand Down
2 changes: 1 addition & 1 deletion slf4j-osgi-integration-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion slf4j-osgi-test-bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion slf4j-simple/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-parent</artifactId>
<version>1.5.4</version>
<version>1.5.5-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public class StaticLoggerBinder implements LoggerFactoryBinder {
public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();

/**
* Version tag used to check compatibility. The value of this field is
* modified with each release.
*/
//to avoid constant folding by the compiler, VERSION field should *not* be final
public static String VERSION = "1.5.4";
* Declare the version of the SLF4J API this implementation is compiled against.
* The value of this field is usually modified with each release.
*/
// to avoid constant folding by the compiler, this field must *not* be final
public static String REQUESTED_API_VERSION = "1.5.5"; // !final

private static final String loggerFactoryClassStr = SimpleLoggerFactory.class.getName();

Expand Down
Loading

0 comments on commit 2050a4d

Please sign in to comment.