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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to