Fork me on GitHub

Extend sli4j

Exigent users that have the need to integrate not already supported logging framework, can easily do it by following the listed steps:

  1. add the core dependency in the pom.xml:
    <dependency>
      <groupId>org.99soft.guice.sli4j</groupId>
      <artifactId>sli4j-core</artifactId>
      <version>3.3</version>
      <scope>compile</scope>
    </dependency>
  2. Extend the org.nnsoft.guice.sli4j.core.AbstractLoggerInjector, that's the class responsibile of creating and injecting the desired Logger, specifying the Logger type:
    import java.lang.reflect.Field;
    
    import com.acme.MyLogger;
    import com.acme.MyLoggerFactory;
    
    import org.nnsoft.guice.sli4j.core.AbstractLoggerInjector;
    
    public final class AcmeLoggerInjector
        extends AbstractLoggerInjector<MyLogger>
    {
    
        public AcmeLoggerInjector( Field field )
        {
            super( field );
        }
    
        @Override
        protected MyLogger createLogger( Class<?> klass )
        {
            return MyLoggerFactory.getLog( klass );
        }
    
    }
  3. Extend the org.nnsoft.guice.sli4j.core.AbstractLoggingModule, specifying the Logger type and the org.nnsoft.guice.sli4j.core.AbstractLoggerInjector type:
    import com.acme.MyLogger;
    
    import org.nnsoft.guice.sli4j.core.AbstractLoggingModule;
    import com.google.inject.TypeLiteral;
    import com.google.inject.matcher.Matcher;
    
    public final class AcmeLoggingModule
        extends AbstractLoggingModule<MyLogger>
    {
    
        public ACLLoggingModule( Matcher<? super TypeLiteral<?>> matcher )
        {
            super(matcher, AcmeLoggerInjector.class);
        }
    
    }
  4. Plug your new logging module and enjoy ;)