Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

commons-logging logger instances - how to initialize in replicated session objects

Richard Mixon (qwest)

2005-02-11

Replies:

I have been working with Filip Hanik to get failover/session replication
working for my application. Finally it is working quite well. Hooray for
Filip!

However it did uncover one issue with the way I was handling the
commons-logging logger instances in my business objects that I store in
the HTTP session at times.

Given the following class:
public class MyBusinessObject1 implements Serializable {
  private static Log log =
LogFactory.getLog(ClassMeasurementFilter.class);
  <SNIP>
  public void setShowXAxisAsPercentages(boolean
showXAxisAsPercentages) {
    this.showXAxisAsPercentages = showXAxisAsPercentages;
    if (log == null) {
       log = LogFactory.getLog(ClassMeasurementFilter.class);
       log.info("setShowXAxisAsPercentages - log was null");
    }
    if (log.isDebugEnabled()) log.debug("setShowXAxisAsPercentages
set to "+this.showXAxisAsPercentages);
  }
  <SNIP>

I had to put the "if (log == null)" check in because when the objects
were replicated to another cluster instance and failover occured I would
get an NPE on the "log" variable.

Obviously having to put this "if (log == null)" check in is very awkward
and error prone.

Other approaches include creating a utility method in the base class for
my business objects. I'm not sure if this will give me the "logger per
class" that I've been used to so that I can readily identify where log
messages come from.

Are there any other approaches anyone would suggest?

Thank you - Richard


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.