You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2003/03/19 08:27:57 UTC

cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger LoggerBase.java

costin      2003/03/18 23:27:57

  Modified:    catalina/src/share/org/apache/catalina/logger
                        LoggerBase.java
  Log:
  Registration for loggers.
  
  We do need to make a final decision about this. I didn't get any feedback on the
  logger names used in context  ( with the context path as prefix of the logger name ).
  IMO the logging in tomcat should be delegated via commons-logging to an external
  implementation - either jdk1.4 logging or log4j.
  
  We do need to decide on the names of the loggers and provide some default
  configs, and eventually start bundling log4j or config files for jdk1.4 ( or
  both ). If we do that, LoggerBase and all other classes will remain only
  for backward compatibility.
  
  Revision  Changes    Path
  1.2       +123 -9    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger/LoggerBase.java
  
  Index: LoggerBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger/LoggerBase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LoggerBase.java	18 Jul 2002 16:48:01 -0000	1.1
  +++ LoggerBase.java	19 Mar 2003 07:27:57 -0000	1.2
  @@ -69,10 +69,20 @@
   import java.beans.PropertyChangeListener;
   import java.io.CharArrayWriter;
   import java.io.PrintWriter;
  +import java.util.Set;
   import javax.servlet.ServletException;
  +import javax.management.ObjectName;
  +import javax.management.MBeanServer;
  +import javax.management.MBeanRegistration;
   import org.apache.catalina.Container;
   import org.apache.catalina.LifecycleException;
   import org.apache.catalina.Logger;
  +import org.apache.catalina.Lifecycle;
  +import org.apache.catalina.core.StandardEngine;
  +import org.apache.catalina.core.StandardHost;
  +import org.apache.catalina.core.StandardContext;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   
   /**
  @@ -84,10 +94,11 @@
    * @version $Revision$ $Date$
    */
   
  -public abstract class LoggerBase
  -    implements Logger {
  -
  -
  +public class LoggerBase
  +    implements Logger, MBeanRegistration 
  + {
  +    private static Log log = LogFactory.getLog(LoggerBase.class);
  +    
       // ----------------------------------------------------- Instance Variables
   
   
  @@ -252,7 +263,9 @@
        * @param message A <code>String</code> specifying the message to be
        *  written to the log file
        */
  -    public abstract void log(String msg);
  +    public void log(String msg) {
  +        log.info(msg);
  +    }
   
   
       /**
  @@ -349,5 +362,106 @@
   
       }
   
  +    protected String domain;
  +    protected String host;
  +    protected String path;
  +    protected ObjectName oname;
  +    protected ObjectName controller;
  +    protected MBeanServer mserver;
  +
  +    public ObjectName getController() {
  +        return controller;
  +    }
  +
  +    public void setController(ObjectName controller) {
  +        this.controller = controller;
  +    }
  +
  +    public ObjectName getObjectName() {
  +        return oname;
  +    }
  +
  +    public String getDomain() {
  +        return domain;
  +    }
  +
  +    public ObjectName preRegister(MBeanServer server,
  +                                  ObjectName name) throws Exception {
  +        oname=name;
  +        mserver=server;
  +        domain=name.getDomain();
  +
  +        host=name.getKeyProperty("host");
  +        path=name.getKeyProperty("path");
  +
  +        if( container== null ) {
  +            // Register with the parent
  +            try {
  +                ObjectName cname=null;
  +                if( host == null ) {
  +                    // global
  +                    cname=new ObjectName(domain +":type=Engine");
  +                } else if( path==null ) {
  +                    cname=new ObjectName(domain +
  +                            ":type=Host,host=" + host);
  +                } else {
  +                    cname=new ObjectName(domain +":j2eeType=WebModule,name=//" +
  +                            host + "/" + path);
  +                }
  +                log.info("Register with " + cname);
  +                mserver.invoke(cname, "setLogger", new Object[] {this},
  +                        new String[] {"org.apache.catalina.Logger"});
  +            } catch (Exception e) {
  +                e.printStackTrace();  //To change body of catch statement use Options | File Templates.
  +            }
  +        }
  +                
  +        return name;
  +    }
  +
  +    public void postRegister(Boolean registrationDone) {
  +    }
  +
  +    public void preDeregister() throws Exception {
  +    }
   
  +    public void postDeregister() {
  +    }
  +
  +    public void init() {
  +        
  +    }
  +    
  +    public void destroy() {
  +        
  +    }
  +    
  +    public ObjectName createObjectName() {
  +        // register
  +        try {
  +            StandardEngine engine=null;            
  +            String suffix="";
  +            if( container instanceof StandardEngine ) {
  +                engine=(StandardEngine)container;                
  +            } else if( container instanceof StandardHost ) {
  +                engine=(StandardEngine)container.getParent();
  +                suffix=",host=" + container.getName();
  +            } else if( container instanceof StandardContext ) {
  +                engine=(StandardEngine)container.getParent().getParent();
  +                suffix=",host=" + container.getParent().getName() + 
  +                        ",path=" + ((StandardContext)container).getPath();
  +            } else {
  +                log.error("Unknown container " + container );
  +            }
  +            if( engine != null ) {
  +                oname=new ObjectName(engine.getDomain()+ ":type=Logger" + suffix);
  +            } else {
  +                log.error("Null engine !! " + container);
  +            }
  +        } catch (Throwable e) {
  +            e.printStackTrace();  //To change body of catch statement use Options | File Templates.
  +        }
  +        return oname;
  +    }
  +    
   }
  
  
  

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


Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger LoggerBase.java

Posted by Bill Barker <wb...@wilshire.com>.
----- Original Message -----
From: <co...@apache.org>
To: <ja...@apache.org>
Sent: Tuesday, March 18, 2003 11:27 PM
Subject: cvs commit:
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/logger
LoggerBase.java


> costin      2003/03/18 23:27:57
>
>   Modified:    catalina/src/share/org/apache/catalina/logger
>                         LoggerBase.java
>   Log:
>   Registration for loggers.
>
>   We do need to make a final decision about this. I didn't get any
feedback on the
>   logger names used in context  ( with the context path as prefix of the
logger name ).
>   IMO the logging in tomcat should be delegated via commons-logging to an
external
>   implementation - either jdk1.4 logging or log4j.
>
>   We do need to decide on the names of the loggers and provide some
default
>   configs, and eventually start bundling log4j or config files for jdk1.4
( or
>   both ). If we do that, LoggerBase and all other classes will remain only
>   for backward compatibility.
>

+1, but we need to at least support Ceki's proposal to split web-app logging
by ContextClassLoader.  Easy enough to do in 3.3.2-dev (yes, well, it's
still on my plate :), and should be almost as easy in 5.x.



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