[weld-dev] How to obtain logger in an interceptor?

Mark Struberg struberg at yahoo.de
Mon May 17 15:18:45 EDT 2010


Hi!

I did read over my mail again and recognized that it was not 100% clear.

In fact I mix up 2 things in 1 sentence:

a) watch your back if you use Interceptors or even NormalScoped bean proxies for highly performance intense tasks. I'm talking of 100.000 invocations per page hit... Let's not make the same mistakes most of us did back in EJB1 or EJB2 where we started to model every small class as EJB. I'm not talking of your perf4j now but about business code in general.

b) Loggers are usually produced as @Dependent, so there is no @NormalScoped proxy involved. But you still need to create a Serializable delegation instance (Interceptors must be Serializable if they get applied to beans with passivatable scope). And this delegation stuff also costs a bit performance (not as bad as proxies though). 
The thing is that you wrote:
> unified way in CDI to obtain a logger in an interceptor?
So most likely the cost of the SerializableLogger would be negligible compared to the cost of the interceptor handling which you need for your performance traces.


LieGrue,
strub


--- On Mon, 5/17/10, Marcin Zajączkowski <mszpak at wp.pl> wrote:

> From: Marcin Zajączkowski <mszpak at wp.pl>
> Subject: Re: [weld-dev] How to obtain logger in an interceptor?
> To: weld-dev at lists.jboss.org
> Date: Monday, May 17, 2010, 6:53 PM
> On 2010-05-16 23:19, Pete Muir
> wrote:
> > Mark is right, but it goes deeper than whether there
> is a logger you can inject to whether there is a common
> logging interface for use with CDI - there isn't as part of
> CDI itself, and for Weld and Seam we are currently using
> slf4j as an abstraction. I would suggest choosing this, and
> making it a dependency of your extension. If you want to
> avoid this, you must use JUL, but that has a horrible API
> (not just around serializability, but also the API
> itself)...
> 
> Thanks guys for your replies.
> 
> I haven't looked at my interceptor from a performance point
> of view, but
> in performance statistics logger is usually heavy used and
> it could be a
> problem.
> 
> 
> Regards
> Marcin
> 
> 
> > 
> > 
> > 
> > On 16 May 2010, at 05:45, Mark Struberg wrote:
> > 
> >> Hoi Marcin!
> >>
> >> You'd like to get an honest answer?
> >>
> >> You know the old saying with the hammer? "If you
> have a hammer, every problem seems to be a nail."
> >>
> >> My suggestion: Don't use logger Injection for high
> performance debug logging at least.
> >>
> >> There is a lot code running inside the
> NormalScoped proxies MethodHandler, and you most probably
> like to lose as little time as possible.
> >>
> >> In my projects, I also started with that
> appproach, but after looking at the performance (both with
> Weld and OWB) with my yourkit profiler, we decided to step
> back and use classic private static Loggers.
> >>
> >> Also, if you use jul.Logger, then you'd be doomed
> anyway. This beast is not Serializable, and you also cannot
> make a Serializable subclass because it's final...
> >>
> >> CDI is a huge boost in my projects, but there is
> no need to use it for each and every instance creation :)
> >>
> >> LieGrue,
> >> strub
> >>
> >> --- On Sat, 5/15/10, Marcin Zajączkowski <mszpak at wp.pl>
> wrote:
> >>
> >>> From: Marcin Zajączkowski <mszpak at wp.pl>
> >>> Subject: [weld-dev] How to obtain logger in an
> interceptor?
> >>> To: weld-dev at lists.jboss.org
> >>> Date: Saturday, May 15, 2010, 9:33 PM
> >>> Hi,
> >>>
> >>>
> >>> I am working on a Perf4j [1] integration with
> CDI/Weld
> >>> (sister project
> >>> to Seam-Perf4j [2] which offers integration
> with Seam
> >>> 2.2.x). Perf4j
> >>> heavy uses logger for its performance
> statistics.
> >>>
> >>> I would like to ask is there an unified way in
> CDI to
> >>> obtain a logger in
> >>> an interceptor?
> >>>
> >>>
> >>> In Seam 2.2.x I could get logger with:
> >>> org.jboss.seam.log.Logging.getLog(loggerName)
> >>>
> >>> With Weld I don't want to get Weld logger
> directly - I
> >>> would like to be
> >>> compatible with other CDI implementations as
> well.
> >>>
> >>> I have seen Weld's extension for logging, but
> it's rather
> >>> for injection
> >>> logger into "normal" beans, not to obtain it
> explicitly in
> >>> an
> >>> interceptor (it's a producer which calls
> >>> LoggerFactory.getLogger() from
> >>> slf4j which I can do directly).
> >>>
> >>>
> >>> Is it possible to get logger proper for CDI
> implementation
> >>> in context
> >>> which my code is running? Or the best solution
> would be to
> >>> use slf4j
> >>> logger with hope it is already using there?
> >>>
> >>>
> >>> [1] - http://perf4j.codehaus.org/
> >>> [2] - http://seam-perf4j.sourceforge.net/
> >>>
> >>>
> >>> Thanks for your comments
> >>> Marcin
> >>>
> _______________________________________________
> >>> weld-dev mailing list
> >>> weld-dev at lists.jboss.org
> >>> https://lists.jboss.org/mailman/listinfo/weld-dev
> 
> _______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev


      



More information about the weld-dev mailing list