commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@blueyonder.co.uk>
Subject [logging] Advice on static/instance/transient Log variables
Date Wed, 23 Nov 2005 02:11:59 GMT
I recently noticed a change in BeanUtils that indicated its not a good idea
to use static Log variables in a shared classloader environment:

  http://svn.apache.org/viewcvs.cgi?rev=189535&view=rev

Commons Resources uses static Log variables throughout and I'm thinking they
should be changed to instance variables since it will be used in a shared
classloader environment (e.g. webapps). Is this the current advice/good
idea?

If that is a recommended practice, my next thought is should the instance
variables be made transient? I recently had a problem with a Log
implementation not being Serializable, plus it would seem a good idea to not
serialize the Log for all instances that use it. If this is a good idea I'm
thinking that I should access the Log through a private method, so that the
it can be re-initialized after de-serialization (rather than having to
implement custom methods to serialize/deserialize). Something along the
lines of this...

    private transient Log log = LogFactory.getLog(Foo.class);

    public void someMethod() {

        if (getLog().isDebugEnabled()) {
            getLog().debug("Foo message");
        }

    }

    private Log getLog() {
        if (log == null) {
            log = LogFactory.getLog(Foo.class)
        }
        return log;
    }

Feedback/comments/advice would be appreciated.

Niall



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


Mime
View raw message