Mix final non-static logger with a kind of SingletonLoggerFactory

4 messages Options
Embed this post
Permalink
Florian Huonder-2

Mix final non-static logger with a kind of SingletonLoggerFactory

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)

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
[hidden email]
http://www.slf4j.org/mailman/listinfo/user
Chad La Joie

Re: Mix final non-static logger with a kind of SingletonLoggerFactory

Reply Threaded More More options
Print post
Permalink
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
> [hidden email]
> 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
[hidden email], http://www.switch.ch

_______________________________________________
user mailing list
[hidden email]
http://www.slf4j.org/mailman/listinfo/user
Ceki Gulcu

Re: Mix final non-static logger with a kind of SingletonLoggerFactory

Reply Threaded More More options
Print post
Permalink
In reply to this post by Florian Huonder-2

Hello Florian,

You probably don't have 10'000 classes but 10'000 *instances* of a class or a
few classes.

Anyway, you don't have to through a factory because the SLF4J factory will
always return the same instance. Do read [1] for more info on this topic.

[1] http://logback.qos.ch/manual/loggingSeparation.html

Cheers,

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
>

--
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
_______________________________________________
user mailing list
[hidden email]
http://www.slf4j.org/mailman/listinfo/user
Michael Grundvig

unsubscribe

Reply Threaded More More options
Print post
Permalink
unsubscribe

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Ceki Gulcu
Sent: Monday, November 02, 2009 1:12 PM
To: User list for the slf4j project
Subject: Re: [slf4j-user] Mix final non-static logger with a kind of SingletonLoggerFactory


Hello Florian,

You probably don't have 10'000 classes but 10'000 *instances* of a class or a
few classes.

Anyway, you don't have to through a factory because the SLF4J factory will
always return the same instance. Do read [1] for more info on this topic.

[1] http://logback.qos.ch/manual/loggingSeparation.html

Cheers,

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
>

--
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch
_______________________________________________
user mailing list
[hidden email]
http://www.slf4j.org/mailman/listinfo/user
_______________________________________________
user mailing list
[hidden email]
http://www.slf4j.org/mailman/listinfo/user