An open API service indexing awesome lists of open source software.

https://github.com/felixklauke/guice-logback

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.
https://github.com/felixklauke/guice-logback

custom-injection dependency-injection extension google google-guice guice guice-extension logback logback-injection

Last synced: 6 months ago
JSON representation

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.

Awesome Lists containing this project

README

          

# 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](http://maven.apache.org/download.cgi)
- Clone this repo
- Install: ```mvn clean install```

**Maven dependencies**

```xml

de.felix-klauke
google-guice-logback
1.0-SNAPSHOT
compile

```

# 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.

```java
Injector injector = Guice.createInjector(new MyCoolModule(), new LogbackModule());
```

```java
@Override
protected void configure() {
install(new LogbackModule);
}
```

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

```java
@InjectLogback private Logger logger;
```