slf4j icon indicating copy to clipboard operation
slf4j copied to clipboard

Use of standard ServiceLoader

Open aneth-dev opened this issue 10 years ago • 3 comments

Hello, I wrote a patch that use the standard ServiceLoader instead of conventional name classes StaticLoggerBinder, StaticMDCBinder and StaticMarkerBinder. This patch does not contains the test part (I have done my own test with simple, nop and jdk14 implementations).

The only thing to do is to declare implementations in META-INF/services directory. See the example below for simple implementation and basic marker and MDC: $ cat META-INF/services/org.slf4j.ILoggerFactory org.slf4j.impl.SimpleLoggerFactory $ cat META-INF/services/org.slf4j.IMarkerFactory org.slf4j.helpers.BasicMarkerFactory $ cat META-INF/services/org.slf4j.MDCAdapter org.slf4j.helpers.BasicMDCAdapter

In this manner, several implementation may be in classpath. But most importantly, this avoids the tedious and inelegant multiple implementation of classes with conventional names.

Best regards, Thomas Pérennou

aneth-dev avatar Mar 15 '14 22:03 aneth-dev

I think that you need to fix indentation, because slf4j uses 2 spaces instead of tabs.

garcia-jj avatar Mar 15 '14 23:03 garcia-jj

Oops, now I remember: ServiceLoader is only available in JDK 6. And SLF4J needs to run under JDK 5.

garcia-jj avatar Mar 15 '14 23:03 garcia-jj

Sorry for you, I sympathized. I'm going to use this patch in my corner…

aneth-dev avatar Mar 15 '14 23:03 aneth-dev