Skip to content

Use google guice custom dependency injection to inject logback loggers. Makes it very easy to create class depending loggers instead of default java.util.Logger injection.

License

Notifications You must be signed in to change notification settings

felixklauke/guice-logback

Repository files navigation

Logback Custom Injection for Google Guice

Ever tried dependency injection while you still want class specific logging? If you don't want to break the sense of dependency injection you shouldn't use a static factory in each class. Google Guice even supports logger injection but sadly only for the default java.util.Logger. Be serious: Who really uses this in production on enterprise level? We wan't custom injection of our own logging framework. In this case we will use logback as our logging framework.

Usage

  • Install Maven
  • Clone this repo
  • Install: mvn clean install

Maven dependencies

<dependency>
    <groupId>de.felix-klauke</groupId>
    <artifactId>google-guice-logback</artifactId>
    <version>1.0-SNAPSHOT</version>
    <scope>compile</scope>
</dependency>

Example / How To

First you will have to install our module in your injector. You can put the module in the injector creation or install our module in your main module.

Injector injector = Guice.createInjector(new MyCoolModule(), new LogbackModule());
@Override
protected void configure() {
    install(new LogbackModule);
}

As soon as the module is installed you can use on any field:

@InjectLogback private Logger logger;

About

Use google guice custom dependency injection to inject logback loggers. Makes it very easy to create class depending loggers instead of default java.util.Logger injection.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages