Users that want to use the SLF4J package and let Guice injects automagically org.slf4j.Logger instances, have to add the following dependency in the pom.xml:
<dependency>
<groupId>com.google.code.sli4j</groupId>
<artifactId>sli4j-slf4j</artifactId>
<version>XX.XX</version>
<scope>compile</scope>
</dependency>
then, when creating the com.google.inject.Injector, add the com.google.code.sli4j.slf4j.Slf4jLoggingModule module; please take note that users have to specify the classes com.google.inject.matcher.Matcher for whom the logging injection has to be applied:
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.code.sli4j.slf4j.Slf4jLoggingModule;
import com.google.inject.matcher.Matchers;
...
Injector injector = Guice.createInjector(new Slf4jLoggingModule(Matchers.any()),
...
);
and the magic happens :)
The module above uses the org.slf4j.LoggerFactory to create org.slf4j.Logger instances, but sli4j comes with native SLF4J bindings, resumed in the following table:
| binding | groupId | artifactId | module class |
|---|---|---|---|
| nop | com.google.code.sli4j | sli4j-slf4j-nop | com.google.code.sli4j.slf4j.nop.Slf4jNopLoggingModule |
| simple | com.google.code.sli4j | sli4j-slf4j-simple | com.google.code.sli4j.slf4j.simple.Slf4jSimpleLoggingModule |
| log4j12 | com.google.code.sli4j | sli4j-slf4j-log4j | com.google.code.sli4j.slf4j.log4j.Slf4jLog4jLoggingModule |
| jdk14 | com.google.code.sli4j | sli4j-slf4j-jdk14 | com.google.code.sli4j.slf4j.jdk14.Slf4jJdk14LoggingModule |
| jcl | com.google.code.sli4j | sli4j-slf4j-jcl | com.google.code.sli4j.slf4j.jcl.Slf4jJclLoggingModule |
| logback | com.google.code.sli4j | sli4j-slf4j-logback | com.google.code.sli4j.slf4j.logback.Slf4jLogbackLoggingModule |