commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Inger, Matthew" <In...@Synygy.com>
Subject [logging] ServletContextLogger
Date Wed, 26 May 2004 20:22:18 GMT
Is there any call for a Log implementation which will log
to a javax.servlet.ServletContext object?  I think it would
be good to provide.  It could fit in between the LogFactoryImpl
right before simple logger:


        if ((logClassName == null) && isJdk13LumberjackAvailable()) {
            logClassName =
"org.apache.commons.logging.impl.Jdk13LumberjackLogger";
        }

        if (logClassName == null && isServletAvailable()) {
            logClassName =
"org.apache.commons.logging.impl.ServletContextLogger";
        }

        if (logClassName == null) {
            logClassName = "org.apache.commons.logging.impl.SimpleLog";
        }

As far as initialization, it could provide a static method (since there's
only ever
one ServletContext per web app anyway, a static variable will suffice),
which could
be called from the Servlet's init method.  (I'm open to other suggestions
here, but
it's the only way i see to make this happen)

public class ServletContextLogger {
   private static ServletContext context;

   public static synchronized init(ServletContext context) {
      ServletContextLogger.context = context;
   }

   ...
}

If the context has not yet been set, we can do one of two things, and
i'm not sure what the appropriate thing to do is:

   1.  do nothing when a log message is issued

     public void debug(Object message) {
        if (context != null) {
            context.log(toString(message));
        }
      }


   2.  create a SimpleLog for every ServletContextLog, and log the
       message to that SimpleLog instance

     public void debug(Object message) {
        if (context != null) {
            context.log(toString(message));
        }
        else {
            simpleLogger.debug(message);
        }
      }

Any thoughts?

PS:  I'm also willing to create a new implementation of LogFactory which
will discover the available log implementations at runtime, rather than the
compile time strategy which exists now.

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


Mime
View raw message