Hi, Gili. I've just coded this for you.. I hope you digg it ;)
http://digg.com/d3yXEh Cheers, -Adrian jclouds On Fri, Jul 24, 2009 at 2:22 PM, Gili Tzabari<[email protected]> wrote: > > Guys, > > I don't understand your answers. It sounds to me like you're talking > about field injection, not constructor injection. > > I don't want to inject a log into an already-constructed object. I want > to inject a log directly into the class constructor: > > class Foo > { > private final Logger log; > > @Inject > public Foo(Logger log) > { > this.log = log; > } > } > > Also, I am not necessarily doing this for jdk loggers so please provide > more detail on how to write a custom injection listener to do this. > > Thanks, > Gili > > Adrian Cole wrote: >> If just injecting a log class, you're right: that's trivial. The >> less trivial part is setting the log scope relevant to the object >> being constructed. >> >> -Adrian >> >> On Fri, Jul 24, 2009 at 10:51 AM, Dhanji R. Prasanna<[email protected]> wrote: >>> You can also write a trivial injection listener that looks for whatever >>> logging class you like and set it after construction. >>> Dhanji. >>> >>> On Fri, Jul 24, 2009 at 5:49 PM, Adrian Cole <[email protected]> wrote: >>>> In jclouds, we use a similar approach, but don't bind ourselves to >>>> java or log4j: >>>> http://code.google.com/p/jclouds/wiki/LogDesign >>>> >>>> Here's the configuration class that may help you do what you are looking >>>> for: >>>> >>>> http://code.google.com/p/jclouds/source/browse/trunk/core/src/main/java/org/jclouds/logging/config/BindLoggersAnnotatedWithResource.java >>>> >>>> I hope this helps, >>>> -Adrian >>>> jclouds >>>> >>>> On Fri, Jul 24, 2009 at 6:15 AM, Dhanji R. Prasanna<[email protected]> >>>> wrote: >>>>> You can already do this with jdk loggers. >>>>> Dhanji. >>>>> >>>>> On Fri, Jul 24, 2009 at 2:12 PM, Gili <[email protected]> wrote: >>>>>> Hi, >>>>>> >>>>>> Is it possible to implement Log4JMembersInjector -- as found here: >>>>>> http://code.google.com/p/google-guice/wiki/CustomInjections -- but for >>>>>> constructor injection instead? That is, I'd like Guice to be smart >>>>>> enough to inject the correct Logger instance into the constructor >>>>>> automatically. I took a look at InjectionListener but it seems to hook >>>>>> instances that have already been injected. Another approach that comes >>>>>> to mind is: >>>>>> >>>>>> @Provides >>>>>> public Logger getLogger(Class<?> outerClass); >>>>>> >>>>>> If I could somehow get Guice to pass in the correct Class... Any >>>>>> ideas? >>>>>> >>>>>> Gili >>>>>> >>>>> >>>> >>> >> >> > >> > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
