diff --git a/slf4j-jdk-platform-logging/src/main/resources/META-INF/services/java.lang.System$LoggerFinder b/slf4j-jdk-platform-logging/src/main/resources/META-INF/services/java.lang.System$LoggerFinder index 36c32dec..06845269 100644 --- a/slf4j-jdk-platform-logging/src/main/resources/META-INF/services/java.lang.System$LoggerFinder +++ b/slf4j-jdk-platform-logging/src/main/resources/META-INF/services/java.lang.System$LoggerFinder @@ -1 +1 @@ -package org.slf4j.jdk.platform.logging.SLF4JSystemLoggerFinder \ No newline at end of file +org.slf4j.jdk.platform.logging.SLF4JSystemLoggerFinder diff --git a/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/SLF4JPlatformLoggingTest.java b/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/test/SLF4JPlatformLoggingTest.java similarity index 93% rename from slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/SLF4JPlatformLoggingTest.java rename to slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/test/SLF4JPlatformLoggingTest.java index 1cd9a120..77f63f8c 100644 --- a/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/SLF4JPlatformLoggingTest.java +++ b/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/test/SLF4JPlatformLoggingTest.java @@ -22,7 +22,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ -package org.slf4j.jdk.platform.logging; +package org.slf4j.jdk.platform.logging.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -57,6 +57,8 @@ public class SLF4JPlatformLoggingTest { static final String SIMPLE_LOGGER_FILE_PROPERTY = PREFIX + "logFile"; static final String SIMPLE_LOGGER_THREAD_NAME_PROPERTY = PREFIX + "showThreadName"; + static final String EXPECTED_FINDER_CLASS = "org.slf4j.jdk.platform.logging.SLF4JSystemLoggerFinder"; + static int diff = new Random().nextInt(100*1000*1000); static final PrintStream oldErr = System.err; @@ -83,6 +85,7 @@ public class SLF4JPlatformLoggingTest { @Test public void smoke() throws IOException { LoggerFinder finder = System.LoggerFinder.getLoggerFinder(); + assertEquals(EXPECTED_FINDER_CLASS, finder.getClass().getName()); Logger systemLogger = finder.getLogger("smoke", null); systemLogger.log(Level.INFO, "hello"); systemLogger.log(Level.INFO, "hello %s", "world"); @@ -96,6 +99,8 @@ public class SLF4JPlatformLoggingTest { @Test public void throwTest() throws IOException { LoggerFinder finder = System.LoggerFinder.getLoggerFinder(); + assertEquals(EXPECTED_FINDER_CLASS, finder.getClass().getName()); + Logger systemLogger = finder.getLogger("throwTest", null); systemLogger.log(Level.INFO, "we have a problem", new Exception()); diff --git a/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/StringPrintStream.java b/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/test/StringPrintStream.java similarity index 96% rename from slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/StringPrintStream.java rename to slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/test/StringPrintStream.java index 821e9b89..b51e1cd2 100644 --- a/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/StringPrintStream.java +++ b/slf4j-jdk-platform-logging/src/test/java/org/slf4j/jdk/platform/logging/test/StringPrintStream.java @@ -22,7 +22,7 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ -package org.slf4j.jdk.platform.logging; +package org.slf4j.jdk.platform.logging.test; import java.io.PrintStream; import java.util.ArrayList; @@ -35,7 +35,7 @@ public class StringPrintStream extends PrintStream { PrintStream other; boolean duplicate = false; - public List stringList = Collections.synchronizedList(new ArrayList<>()); + public List stringList = Collections.synchronizedList(new ArrayList()); public StringPrintStream(PrintStream ps, boolean duplicate) { super(ps); diff --git a/slf4j-site/src/site/pages/faq.html b/slf4j-site/src/site/pages/faq.html index 6ed1f313..44383d68 100755 --- a/slf4j-site/src/site/pages/faq.html +++ b/slf4j-site/src/site/pages/faq.html @@ -67,8 +67,8 @@
  • - Where can I get a particular - SLF4J provider? + Where can I get a particular + SLF4J provider/binding?
  • @@ -234,14 +234,14 @@

    Suppose that your CRM application uses log4j for its logging. However, one of your important clients request that - logging be performed through JDK 1.4 logging. If your - application is riddled with thousands of direct log4j calls, - migration to JDK 1.4 would be a relatively lengthy and - error-prone process. Even worse, you would potentially need to - maintain two versions of your CRM software. Had you been - invoking SLF4J API instead of log4j, the migration could be - completed in a matter of minutes by replacing one jar file with - another. + logging be performed through java.util.Logging, a.k.a. JDK 1.4 + logging. If your application is riddled with thousands of direct + log4j calls, migration to java.util.logging would be a + relatively lengthy and error-prone process. Even worse, you + would potentially need to maintain two versions of your CRM + software. Had you been invoking SLF4J API instead of log4j, the + migration could be completed in a matter of minutes by replacing + one jar file with another.

    SLF4J lets component developers to defer the choice of the @@ -274,11 +274,12 @@

    This is a very good question. First, SLF4J static binding - approach is very simple, perhaps even laughably so. It was - not easy to convince developers of the validity of that - approach. It is only after SLF4J was released and started to - become accepted did it gain respectability in the relevant - community. + approach is very simple, perhaps even laughably so. It was not + easy to convince developers of the validity of that + approach. Note that as of version 2.0.0, SLF4J uses the + ServiceLoader mechanism offered by the Java + platform. This new approach is still relatively static and + therefore predictable.

    Second, SLF4J offers two enhancements which tend to be @@ -290,7 +291,10 @@ open to switching back to more traditional logging systems if need be.

    - + +

    In 2021, the question is moot since JCL has been defunct for + at least a decade. +

    @@ -302,14 +306,15 @@

    No, you do not need to recompile your application. You can switch to a different logging system by removing the previous - SLF4J binding and replacing it with the binding of your choice. + SLF4J provider and replacing it with the provider of your + choice.

    For example, if you were using the NOP implementation and would like to switch to log4j version 1.2, simply replace slf4j-nop.jar with slf4j-log4j12.jar on your class path but do not forget to add log4j-1.2.x.jar as - well. Want to switch to JDK 1.4 logging? Just replace + well. Want to switch to java.util.logging? Just replace slf4j-log4j12.jar with slf4j-jdk14.jar.

    @@ -322,40 +327,39 @@
    -

    As of version 1.7.0, SLF4J requires JDK 1.5 or later. Earlier - SLF4J versions, namely SLF4J 1.4, 1.5. and 1.6, required JDK - 1.4. +

    As of version 2.0.0, SLF4J requires JDK 8 or later. Version + 1.7.0 requires JDK 1.5 or later.

     

    - + - + - + - - + - @@ -403,7 +407,7 @@ slf4j-api and slf4j-simple versions are placed on the class path. Please note that the table below applies by analogy not just to slf4j-simple but also to other providers such as - slf4j-log4j12, logback-classic, slf4j-jul14, etc... + slf4j-log4j12, logback-classic, slf4j-jdk14, etc...

    @@ -426,7 +430,7 @@ - @@ -476,6 +480,10 @@ said mismatch.

    +

    Fluent API requires version 2.0 If + your code accesses the fluent API introduced in slf4j 2.0, then + your code will require version 2.0 or later.

    + @@ -520,7 +528,7 @@ org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory

    In your pom.xml file, explicitly declaring a dependency on slf4j-api matching the version of the declared - binding will make the problem go away. + provider/binding will make the problem go away.

    Please also read the FAQ entry on -

    Where can I get a - particular SLF4J provider? +
    Where can I get a + particular SLF4J provider/binding?
    @@ -566,14 +574,14 @@ org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory are contained within the files slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, and slf4j-jdk14.jar. These files can be found on Maven - central. Please note that all providers depend on + central. Please note that all providers/bindings depend on slf4j-api.jar.

    The providers for logback-classic is part of the logback project and can be found - on Maven central. However, as with all other providers, the - logback-classic provider requires slf4j-api.jar. + href="http:logback.qos.ch">logback project and can also be + found on Maven central. However, as with all other providers, + the logback-classic provider requires slf4j-api.jar.

    @@ -678,7 +686,7 @@ org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory logging. While one can come up with a seemingly working SLF4J-wrapper within hours, many technical issues will emerge over time which Wombat developers will have to deal with. Note - that SLF4J has evolved over several years and has 260 bug + that SLF4J has evolved over several years and has 500 bug reports filed against it.

    For the above reasons, developers of frameworks should resist @@ -698,7 +706,7 @@ org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory

    As an author of a library built with Maven, you might want to - test your application using a binding, say slf4j-log4j12 or + test your application using a provider, say slf4j-log4j12 or logback-classic, without forcing log4j or logback-classic as a dependency upon your users. This is rather easy to accomplish.

    @@ -713,9 +721,9 @@ org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory <version>${project.version}</version> </dependency> -

    Limiting the transitivity of the SLF4J binding used in your +

    Limiting the transitivity of the SLF4J provider used in your tests can be accomplished by declaring the scope of the - SLF4J-binding dependency as "test". Here is an example:

    + SLF4J-provider dependency as "test". Here is an example:

    <dependency>
       <groupId>org.slf4j</groupId>
    @@ -726,11 +734,11 @@ org.slf4j.impl.StaticLoggerBinder.SINGLETON from class org.slf4j.LoggerFactory
           
           

    Thus, as far as your users are concerned you are exporting slf4j-api as a transitive dependency of your library, but not - any SLF4J-binding or any underlying logging system. + any SLF4J-provider or any underlying logging system.

    Note that as of SLF4J version 1.6, in the absence of an SLF4J - binding, slf4j-api will default to a no-operation + provider, slf4j-api will default to a no-operation implementation.

    @@ -1344,7 +1352,7 @@ class Bar { around an ILoggerFactory instance. The ILoggerFactory instance in use is - determined according to the static binding conventions of the + determined according to the static provider conventions of the SLF4J framework. See the getSingleton() method in LoggerFactory for details. @@ -1418,7 +1426,7 @@ try {

    Adding supporting for the SLF4J is surprisingly - easy. Essentially, you coping an existing binding and tailoring + easy. Essentially, you coping an existing provider and tailoring it a little (as explained below) does the trick.

    @@ -1451,7 +1459,7 @@ try { existing NOP implementations.

    -

    In summary, to create an SLF4J binding for your logging +

    In summary, to create an SLF4J provider for your logging system, follow these steps:

      @@ -1527,14 +1535,14 @@ try {

      For each version, SLF4J API maintains a list of compatible versions. SLF4J will emit a version mismatch warning only if the requested version is not found in the compatibility - list. So even if your SLF4J binding has a different release + list. So even if your SLF4J provider has a different release schedule than SLF4J, assuming you update the SLF4J version you use every 6 to 12 months, you can still participate in the version check without incurring a mismatch warning. For example, logback has a different release schedule but still participates in version checks.

      -

      As of SLF4J 1.5.5, all bindings shipped within the +

      As of SLF4J 1.5.5, all providers shipped within the SLF4J distribution, e.g. slf4j-log4j12, slf4j-simple and slf4j-jdk14, declare the REQUESTED_API_VERSION field with a value equal to their SLF4J version. It follows that, for example @@ -1595,7 +1603,7 @@ try {

      1. For libraries shared between applications, not possible to take advantage of repository selectors. It - should be noted that if the SLF4J binding and the + should be noted that if the SLF4J provider and the underlying API ships with each application (not shared between applications), then each application will still have its own logging environment. @@ -1681,7 +1689,7 @@ try {

        Unfortunately, for non-native implementations of the SLF4J API, namely with slf4j-log4j12, log4j's repository selector will not be able to do its job properly because slf4j-log4j12, a - non-native SLF4J binding, will store logger instances in a map, + non-native SLF4J provider, will store logger instances in a map, short-circuiting context-dependent logger retrieval. For native SLF4J implementations, such as logback-classic, repository selectors will work as expected.

    BindingProvider Requirements
    slf4j-nopJDK 1.5JDK 8
    slf4j-simpleJDK 1.5JDK 8
    slf4j-log4j12JDK 1.5, plus any other library + JDK 8, plus any other library dependencies required by the log4j appenders in use
    slf4j-jdk14JDK 1.5 or laterJDK 8 or later
    logback-classicJDK 1.5 or later, plus any other library dependencies + JDK 8 or later, plus any other library dependencies required by the logback appenders in use
    1.7.x 2.0.x no bindings can be found warning messageA 2.0.x providers do not act as 1.7.x/16.x + 2.0.x providers do not act as 1.7.x/16.x comptatible bindings