slf4j
slf4j copied to clipboard
Use of standard ServiceLoader
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
I think that you need to fix indentation, because slf4j uses 2 spaces instead of tabs.
Oops, now I remember: ServiceLoader is only available in JDK 6. And SLF4J needs to run under JDK 5.
Sorry for you, I sympathized. I'm going to use this patch in my corner…