On 24 September 2010 15:36, Jason van Zyl <[email protected]> wrote:
> This is the patch that we use in Sisu (Sonatype's patched version of Guice) > to allow the injection of SL4J and JUL loggers. > > http://code.google.com/p/google-guice/issues/detail?id=492 > just to be clear, this patch allows injection of SLF4J loggers using @Inject which then also lets you inject the logger via the constructor parameters the other approach (using @InjectLogger TypeListeners) only works when injecting fields or setter methods, because custom injection only kicks in after the object being injected has been constructed -- Cheers, Stuart > Github repo is here: > > http://github.com/sonatype/sisu-guice > > On Sep 24, 2010, at 5:46 AM, Asier wrote: > > Hi > > I've followed instructions from > > http://glauche.de/2009/08/24/logging-with-slf4j-and-guice/ > > To inject loggers via @InjectLogger tags, but this loggers are only > available after the constructor has been executed. > > class A { > > @InjectLogger private Logger logger; > private final SomeClass someClass; > > @Inject > A(SomeClas someClass) implements IA { > logger.debug("Initializing A"); > this.someClass = someClass; > } > > // ... > } > > Fails with a: > > | com.google.inject.CreationException: Guice creation errors: > | > | 1) Error injecting constructor, java.lang.NullPointerException > | ... > > How can I have a logger injected and usable in the constructor? > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > > > Thanks, > > Jason > > ---------------------------------------------------------- > Jason van Zyl > Founder, Apache Maven > http://twitter.com/jvanzyl > --------------------------------------------------------- > > A man enjoys his work when he understands the whole and when he > is responsible for the quality of the whole > > -- Christopher Alexander, A Pattern Language > > > > > > Thanks, > > Jason > > ---------------------------------------------------------- > Jason van Zyl > Founder, Apache Maven > http://twitter.com/jvanzyl > --------------------------------------------------------- > > We all have problems. How we deal with them is a measure of our worth. > > -- Unknown > > > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-guice%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-guice?hl=en. > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice?hl=en.
