logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Java House <java4...@gmail.com>
Subject Re: static logger
Date Sat, 05 Jul 2008 16:37:33 GMT
Great suggestion!!!
I think this will keep me happy and satisfy library's recomendations.


O/H Thorbjørn Ravn Andersen έγραψε:
> Java House skrev  den 05-07-2008 18:10:
>> O/H Thorbjørn Ravn Andersen έγραψε:
>>> Java House skrev  den 05-07-2008 16:27:
>>>> How bad is it, to NOT use static logger;
>>> By having the logger variable static it means it is only initialized 
>>> once when the class is loaded where as a non-static logger is 
>>> initialized each time you create a new object from the class.  If 
>>> you do this a lot there might be a substantial overhead which is 
>>> often unnecessary if the logger is the same for all objects.
>> I understand this.
> I believe that is why it is disrecommended.
>>> Please note that the object may be used by more than one thread so 
>>> you should be aware that this might trick your RepositorySelector.
>> But this is exactly the problem I have by using a static logger 
>> object. The logger variable gets value from the last instantiated 
>> object which is any of the threads in question. The only way to make 
>> this work is if the logger object is not static.
> Are you familiar with the ThreadLocal class?  Sounds to me that that 
> is what you might want to look into.
> http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html

To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org

View raw message