Fork me on GitHub

Simple Logging Facade for Java (SLF4J)

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>org.99soft.guice.sli4j</groupId>
  <artifactId>sli4j-slf4j</artifactId>
  <version>3.3</version>
  <scope>compile</scope>
</dependency>

then, when creating the com.google.inject.Injector, add the org.nnsoft.guice.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 org.nnsoft.guice.sli4j.slf4j.Slf4jLoggingModule;
import com.google.inject.matcher.Matchers;

...

Injector injector = Guice.createInjector( new Slf4jLoggingModule( Matchers.any() ),
    ...
);

and the magic happens :)