[slf4j-user] Mix final non-static logger with a kind of SingletonLoggerFactory
Florian Huonder
fhuonder at herasaf.org
Mon Nov 2 09:42:26 CET 2009
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://qos.ch/pipermail/slf4j-user/attachments/20091102/238f81a0/attachment.htm>
More information about the slf4j-user
mailing list