[slf4j-dev] [JIRA] Updates for SLF4J-548: Loading services (plugins) with the caller's ClassLoader

QOS.CH (JIRA) noreply-jira at qos.ch
Sat Apr 30 17:47:00 CEST 2022


SLF4J / SLF4J-548 [Open]
Loading services (plugins) with the caller's ClassLoader

==============================

Here's what changed in this issue in the last few minutes.
This issue has been created
This issue is now assigned to you.

View or comment on issue using this link
https://jira.qos.ch/browse/SLF4J-548

==============================
 Issue created
------------------------------

pierre created this issue on 30/Apr/22 5:32 PM
Summary:              Loading services (plugins) with the caller's ClassLoader
Issue Type:           Improvement
Affects Versions:     1.8.0-beta4
Assignee:             SLF4J developers list
Components:           Core API
Created:              30/Apr/22 5:32 PM
Priority:             Major
Reporter:             pierre
Description:
  Hi,
  
  First of all congratulations and thank you for this excellent API.
  
  I want to use your Slf4j API in my JDBC driver for the Uno LibreOffice / OpenOffice API. I want to use it to redirect loggers from HsqlDB and H2 to the Uno Logger API, but I can't use it without modifying the slf4j-api.jar service loader. Let me explain my problem. 
  
  
  Services provider or plugins seem to be loaded in the file:
  
  [LoggerFactory.java|https://github.com/qos-ch/slf4j/blob/master/slf4j-api/src/main/java/org/slf4j/LoggerFactory.java#L102]
  
  with the commande: 
  
  {code:java}
  ServiceLoader<SLF4JServiceProvider> serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class);
  {code}
  
  but without ClassLoader who is by default the current Thread's ClassLoader.
  
  My application, a jar file that embeds the slf4j-Api  and a service provider for the Uno Logger archives (slf4j-api.jar and UnoLogger.jar), that wants to use Slf4j is loaded by a URLClassLoader by LibreOffice which extend the CLASSPATH and which has as ClassLoader the current Thread's ClassLoader.
  
  As a result, Services or Plugins can't never see the extended CLASSPATH from my application and never load...
   Would it be possible to load the services with the ClassLoader of the caller:
  
  {code:java}
  ServiceLoader<SLF4JServiceProvider> serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class, LoggerFactory.class.getClassLoader());
  {code}
  
  instead of that of the current Thread.
  
  This will allow CLASSPATH inheritance through ClassLoaders... and this is the normal behaviour of 
  {code:java}
  new Object()
  {code}
   or
  {code:java}
  Class.forName()
  {code}
  
  Thank you.
  


==============================
 This message was sent by Atlassian Jira (v8.8.0#808000-sha1:e2c7e59)



More information about the slf4j-dev mailing list