align with version 2.0.14

Signed-off-by: Ceki Gulcu <ceki@qos.ch>
This commit is contained in:
Ceki Gulcu 2024-08-07 22:47:51 +02:00
parent a735039012
commit 19ca97d751
3 changed files with 74 additions and 6 deletions

View File

@ -198,7 +198,7 @@ public final class LoggerFactory {
// SLF4JServiceProvider.initialize() is intended to be called here and nowhere else.
PROVIDER.initialize();
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION;
reportActualBinding(providersList);
reportActualBinding(PROVIDER);
} else {
INITIALIZATION_STATE = NOP_FALLBACK_INITIALIZATION;
Reporter.warn("No SLF4J providers were found.");
@ -405,11 +405,8 @@ public final class LoggerFactory {
}
}
private static void reportActualBinding(List<SLF4JServiceProvider> providerList) {
if (!providerList.isEmpty()) {
SLF4JServiceProvider provider = providerList.get(0);
Reporter.info(CONNECTED_WITH_MSG + provider.getClass().getName() + "]");
}
private static void reportActualBinding(SLF4JServiceProvider provider) {
Reporter.info(CONNECTED_WITH_MSG + provider.getClass().getName() + "]");
}
/**

View File

@ -0,0 +1,50 @@
package org.slf4j.helpers;
import java.lang.module.ModuleDescriptor;
import java.util.Optional;
public class Slf4jEnvUtil {
/**
* <p>Returns the current version of logback, or null if data is not
* available.
* </p>
*
* @return current version or null if missing version data
* @since 1.3.0
*/
static public String slf4jVersion() {
String moduleVersion = slf4jVersionByModule();
if(moduleVersion != null)
return moduleVersion;
Package pkg = Slf4jEnvUtil.class.getPackage();
if(pkg == null) {
return null;
}
final String pkgVersion = pkg.getImplementationVersion();
return pkgVersion;
}
/**
* <p>Returns the current version of logback via class.getModule() or null if data is not
* available.
* </p>
*
* @since 1.3.0
* @return current version or null if missing version data
*/
static private String slf4jVersionByModule() {
Module module = Slf4jEnvUtil.class.getModule();
if (module == null)
return null;
ModuleDescriptor md = module.getDescriptor();
if (md == null)
return null;
Optional<String> opt = md.rawVersion();
return opt.orElse(null);
}
}

View File

@ -0,0 +1,21 @@
package org.slf4j.simple;
import org.junit.Test;
import org.slf4j.helpers.Slf4jEnvUtil;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class Slf4jVersionTest {
@Test
public void slf4jVersionTest() {
String version = Slf4jEnvUtil.slf4jVersion();
assertNotNull(version);
assertTrue(version.startsWith("2"));
}
}