[slf4j-user] Is it not safe to store the Logger instance into a static field?

Ceki Gülcü listid at qos.ch
Thu Mar 16 18:24:27 CET 2006


At 11:33 AM 3/5/2006, Simon Kitching wrote:

<snip/>

>I've created a page specifically on this problem here:
>http://wiki.apache.org/jakarta-commons/Logging/StaticLog
>
>As this is a somewhat complicated issue this page may well need
>correction/improvement. This page is on a wiki so *can* be edited by any
>logged-in person. However the issues involved are complex, so if anyone
>out there wishes to make corrections then unless you are *absolutely*
>certain you are right I would request that you reply to this thread,
>post on commons-dev with subject [logging] or email me direct for
>discussion before editing that page.

Instance log variables present the advantage of associating the host object 
with the correct logging context. However, the approach has two obvious 
disadvantages, which you duly mention in your article. Theyare repeated below:

1) Computational cost of retrieving a logger for each object instance
2) Additional 4 bytes (or is it 8?) in each object instance to hold a 
reference to the logger object, instead of a single reference for the whole 
class.

I believe Item 1 can be brought under control. I am not so sure about Item 
2. Assuming the JVM creates many small objects, adding another reference to 
each instance can have a non-negligible impact. Does anyone know the memory 
footprint occupied by the smallest object instance? What is the impact a 
log reference in each instance?



>Simon

-- 
Ceki Gülcü
http://ceki.blogspot.com/




More information about the slf4j-user mailing list