You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by wolverine my <wo...@gmail.com> on 2007/05/21 04:42:00 UTC

What about a static logger?

Hi!

Does it matters if we declared the logger as static or a instance variable?

It seem to me that the static logger has more advantage as it can be
used in static scope/method.

What is the best practice of declaring a logger?

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


Re: What about a static logger?

Posted by Jacob Kjome <ho...@visi.com>.
At 09:42 PM 5/20/2007, you wrote:
 >Hi!
 >
 >Does it matters if we declared the logger as static or a instance variable?
 >
 >It seem to me that the static logger has more advantage as it can be
 >used in static scope/method.
 >
 >What is the best practice of declaring a logger?
 >

A nice synopsis of this issue has been written by the commons-logging team....

http://wiki.apache.org/jakarta-commons/Logging/StaticLog


One thing that isn't mentioned is the issue of Serialization.  If you 
have a non-static logger in a Serializable class, you need to mark is 
as "transient" or you will be breaking the Serialization contract 
(and get nasty NotSerializableException stack traces, likely along 
with application failure).  Loggers are NOT Serializable.  You would 
be advised to either make the logger static or transient.  If you 
make it transient, then don't forget to implement readObject and set 
up the logger again or it will be null in the deserialized instance 
of the class.

Jake 


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