[slf4j-user] Mix final non-static logger with a kind of SingletonLoggerFactory

Chad La Joie chad.lajoie at switch.ch
Mon Nov 2 09:49:43 CET 2009


Hey Florian,

I believe SLF4j does logger object caching, so that when you call 
LoggerFactory.getLogger(MyClass.class) it will produce a logger object 
once, cache it, and return it for each additional call.

Ceki can correct me if I'm wrong about this.

Florian Huonder wrote:
> Hi all,
> 
>  
> 
> I have a little question how to use slf4j correctly.
> 
>  
> 
> We use SLF4J as logging frontend in a framework.
> 
> There are lots of classes that contain business logic. These classes are
> initialized once.
> 
> Here we have the following signature for the loggers  "private final Logger
> logger = LoggerFactory.getLogger(MyClass.class);".
> 
> On the other hand there are a lot of domain classes. In a productive
> environment it is possible that there are 10'000 or 100'000s of domain
> classes.
> 
> The domain classes also have to log stuff. I think there it won't be a good
> idea to have the logger static.
> 
> But then the drawbacks of static occur (not ioc friendly, unknown behavior
> because the logger is JVM wide the same).
> 
>  
> 
> We thought about the following solution but are not sure if SLF4J can be
> used like that :
> 
> All business-logic classes that are initialized once get the logger like
> written above :"private final Logger logger =
> LoggerFactory.getLogger(MyClass.class);".
> 
> The domain classes are created through a factory. In this factory we have a
> call like "private final Logger logger =
> MySingletonLoggerFactory.getLogger(MyDomainClass.class) ;"
> 
> The MySingletonLoggerFactory class then is responsible of returning the same
> logger for each type of domain object.
> 
>  
> 
> What do you think about the solution?
> 
> Is this a feasible way ? Are there better ways to go?
> 
>  
> 
> I am really looking forward to hearing from you.
> 
>  
> 
> Regards,
> 
> Florian
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> user mailing list
> user at slf4j.org
> http://www.slf4j.org/mailman/listinfo/user

-- 
SWITCH
Serving Swiss Universities
--------------------------
Chad La Joie, Software Engineer, Net Services
Werdstrasse 2, P.O. Box, 8021 Zürich, Switzerland
phone +41 44 268 15 75, fax +41 44 268 15 68
chad.lajoie at switch.ch, http://www.switch.ch




More information about the slf4j-user mailing list