commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Inger, Matthew" <>
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 =

        if (logClassName == null && isServletAvailable()) {
            logClassName =

        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) {

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

     public void debug(Object message) {
        if (context != null) {
        else {

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:
For additional commands, e-mail:

View raw message