qos-ch/slf4j

org.slf4j.LoggerFactory can not load SLF4JServiceProvider with org.eclipse.osgi.internal.loader.EquinoxClassLoader

Holzmacher opened this issue · 4 comments

In org.slf4j.LoggerFactory the following row:
serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class, classLoaderOfLoggerFactory);
has a problem, if classLoaderOfLoggerFactory is a org.eclipse.osgi.internal.loader.EquinoxClassLoader.

Then the loaded serviceLoader has an empty loadedProviders Array.

Seee also:
https://stackoverflow.com/questions/78783619/logback-logger-1-5-0-with-eclipse-4-31-no-slf4j-providers-were-found/78904640#78904640

SLF4J 2 assumes that a Service Loader Mediator like Apache SPI Fly is present in your OSGi environment. You need to add the bundle to your Equinox deployment.

See also #428.

I would say it would be helpful, if you add this osgi issue to the following manual:
https://www.slf4j.org/codes.html#noProviders

Because you get following output in this case:
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.

ceki commented

@Holzmacher Thank you for following up on this issue. It is much appreciated.

I should observe that the code in initSLF4JServiceProvider creates a second logging system unrelated to the one used by LoggerFactory. Thus, it is not a general solution.

However, it is not clear if the first part of your answer is sufficient and whether initSLF4JServiceProvider was provided for illustration purposes only and is not actually needed.

Can you please clarify?