[slf4j-dev] svn commit: r1307 - slf4j/trunk/slf4j-site/src/site/pages

Thorbjoern Ravn Andersen ravn at runjva.com
Fri Apr 17 16:33:18 CEST 2009


Ceki Gulcu skrev:
>
>>>
>>> See http://slf4j.org/faq.html#declared_static
>>> The official stance is that there is no official stance. :-)
>> If I understand the link correctly the primary reason for 
>> recommending "not static" is to allow repository selectors to work 
>> with logback?
>
> Hmm, I would not word it like that. Static loggers are an issue only 
> for shared libraries which in practice are not such a big deal.
I am afraid I did not understand that reply.  Could you reword it?

>> Do you have benchmark figures already for the overhead of creating a 
>> logger for each object?
>
> You surely know the answer to that. Hint: what is the difference 
> between static fields and instance fields referencing the very same 
> object, in this case the same logger?
I am not making any assumptions here.  A naive implementation would 
create a new logger object for each new instantiation.  I gather from 
your hint that there is a single logger per identifier (class object) 
and that the sole difference is the lookup mechanism (which may even be 
a single map lookup) and the extra object reference in the instantiation 
instead of a single reference in the class.

Is there any scenario to your knowledge where the logger lookup 
mechanism may be slow?

>
>> Am I right in assuming that the logback mechanism for looking up 
>> loggers is faster than in log4j?  There must be a reason for the 
>> original recommandation :)
>
> The reason for the original recommendation was mainly related to 
> serialization which SLF4J did not support in earlier versions. Current 
> SLF4J version support logger serialization so having loggers as a 
> instance variables is no longer a problem.
I was thinking that the original log4j recommendation was to be static, 
which is what I am referring to. 

I fully understand that having instance variables allow different 
objects of the same class to behave differently depending on context as 
opposed to the static version.

I will need to read up on the serialization issue in slf4j (not 
serialization in general) to be able to comment in that context.


>
> Performance between static and instance loggers comes into play if you 
> instantiate many (as in > 100'000) instances of the same class.
Do you have benchmarks of this already or is it an estimate from experience?

-- 
  Thorbjørn Ravn Andersen  "...plus... Tubular Bells!"




More information about the slf4j-dev mailing list