You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2005/03/03 14:34:17 UTC

cvs commit: jakarta-tomcat-connectors/juli/src/java/org/apache/juli ClassLoaderLogManager.java

remm        2005/03/03 05:34:17

  Modified:    .        build.xml
               juli/src/java/org/apache/juli ClassLoaderLogManager.java
  Added:       resources logging.properties
  Log:
  - Add a sample default configuration. Webapps can use their own configuration by having a logging.properties in their own classloader.
  - Properly parse and set handlers.
  - Fix useParentHandlers initialization (it tended to be always set to false).
  - The necessary system property is not present yet, however (-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager is needed
    in JAVA_OPTS or CATALINA_OPTS). Some hacking of the startup scripts is needed.
  
  Revision  Changes    Path
  1.225     +3 -0      jakarta-tomcat-5/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-5/build.xml,v
  retrieving revision 1.224
  retrieving revision 1.225
  diff -u -r1.224 -r1.225
  --- build.xml	2 Mar 2005 18:36:29 -0000	1.224
  +++ build.xml	3 Mar 2005 13:34:17 -0000	1.225
  @@ -307,6 +307,9 @@
   	      </fileset>
   	    </jar>
   
  +	  	<copy file="${basedir}/resources/logging.properties"
  +	  	     todir="${tomcat.build}/common/classes" /> 
  +	  	
   	  </target>
   
     <target name="build-jasper" 
  
  
  
  1.1                  jakarta-tomcat-5/resources/logging.properties
  
  Index: logging.properties
  ===================================================================
  handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4admin.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
  
  .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
  
  ############################################################
  # Handler specific properties.
  # Describes specific configuration info for Handlers.
  ############################################################
  
  1catalina.org.apache.juli.FileHandler.level = FINE
  1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
  1catalina.org.apache.juli.FileHandler.prefix = catalina.
  
  2localhost.org.apache.juli.FileHandler.level = FINE
  2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
  2localhost.org.apache.juli.FileHandler.prefix = localhost.
  
  3manager.org.apache.juli.FileHandler.level = FINE
  3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
  3manager.org.apache.juli.FileHandler.prefix = manager.
  
  4admin.org.apache.juli.FileHandler.level = FINE
  4admin.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
  4admin.org.apache.juli.FileHandler.prefix = admin.
  
  java.util.logging.ConsoleHandler.level = FINE
  java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
  
  
  ############################################################
  # Facility specific properties.
  # Provides extra control for each logger.
  ############################################################
  
  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = java.util.logging.ConsoleHandler, 2localhost.org.apache.juli.FileHandler
  
  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler
  
  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/admin].level = INFO
  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/admin].handlers = 4admin.org.apache.juli.FileHandler
  
  # For example, set the com.xyz.foo logger to only log SEVERE
  # messages:
  #org.apache.catalina.startup.ContextConfig.level = FINE
  #org.apache.catalina.startup.HostConfig.level = FINE
  #org.apache.catalina.session.ManagerBase.level = FINE
  
  
  
  1.5       +30 -47    jakarta-tomcat-connectors/juli/src/java/org/apache/juli/ClassLoaderLogManager.java
  
  Index: ClassLoaderLogManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/juli/src/java/org/apache/juli/ClassLoaderLogManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ClassLoaderLogManager.java	3 Mar 2005 01:51:12 -0000	1.4
  +++ ClassLoaderLogManager.java	3 Mar 2005 13:34:17 -0000	1.5
  @@ -84,9 +84,9 @@
               }
               return unset;
           }
  -        final ClassLoader classLoader = Thread.currentThread()
  -                .getContextClassLoader();
  -        final ClassLoaderLogInfo info = getClassLoaderInfo(classLoader);
  +        ClassLoader classLoader = 
  +            Thread.currentThread().getContextClassLoader();
  +        ClassLoaderLogInfo info = getClassLoaderInfo(classLoader);
           if (info.loggers.containsKey(loggerName)) {
               return false;
           }
  @@ -94,7 +94,7 @@
           info.loggers.put(loggerName, logger);
   
           // apply initial level for new logger
  -        final String levelString = getProperty(loggerName + ".level");
  +        String levelString = getProperty(loggerName + ".level");
           final Level level;
           if (levelString != null) {
               Level parsedLevel = null;
  @@ -133,11 +133,11 @@
           }
   
           // find node
  -        final LogNode node = info.rootNode.findNode(loggerName);
  +        LogNode node = info.rootNode.findNode(loggerName);
           node.logger = logger;
   
           // set parent logger
  -        final Logger parentLogger = node.findParentLogger();
  +        Logger parentLogger = node.findParentLogger();
           if (parentLogger != null) {
               doSetParentLogger(logger, parentLogger);
           }
  @@ -147,13 +147,24 @@
   
           // Add associated handlers, if any are defined using the .handlers property.
           // In this case, handlers of the parent logger(s) will not be used
  -        final String handlers = getProperty(loggerName + ".handlers");
  +        String handlers = getProperty(loggerName + ".handlers");
           if (handlers != null) {
               logger.setUseParentHandlers(false);
               StringTokenizer tok = new StringTokenizer(handlers, ",");
               while (tok.hasMoreTokens()) {
                   String handlerName = (tok.nextToken().trim());
  -                Handler handler = (Handler) info.handlers.get(handlerName);
  +                Handler handler = null;
  +                ClassLoader current = classLoader;
  +                while (current != null) {
  +                    info = (ClassLoaderLogInfo) classLoaderLoggers.get(current);
  +                    if (info != null) {
  +                        handler = (Handler) info.handlers.get(handlerName);
  +                        if (handler != null) {
  +                            break;
  +                        }
  +                    }
  +                    current = current.getParent();
  +                }
                   if (handler != null) {
                       logger.addHandler(handler);
                   }
  @@ -164,10 +175,7 @@
           // Unlike java.util.logging, the default is to not delegate if a list of handlers
           // has been specified for the logger.
           String useParentHandlersString = getProperty(loggerName + ".useParentHandlers");
  -        if ((useParentHandlersString != null) 
  -                && (!Boolean.valueOf(useParentHandlersString).booleanValue())) {
  -            logger.setUseParentHandlers(false);
  -        } else {
  +        if (Boolean.valueOf(useParentHandlersString).booleanValue()) {
               logger.setUseParentHandlers(true);
           }
           
  @@ -189,17 +197,6 @@
           final ClassLoader classLoader = Thread.currentThread()
                   .getContextClassLoader();
           final Map loggers = getClassLoaderInfo(classLoader).loggers;
  -        /*
  -         * Debug: display handler list
  -        Logger logger = (Logger) loggers.get(name);
  -        System.out.println(name);
  -        if (logger != null) {
  -            Handler[] handlers =  logger.getHandlers();
  -            for (int i = 0; i < handlers.length; i++) {
  -                System.out.println("H" + i + ":" + handlers[i]);
  -            }
  -        }
  -        */
           return (Logger) loggers.get(name);
       }
       
  @@ -266,6 +263,11 @@
       }
       
       private ClassLoaderLogInfo getClassLoaderInfo(final ClassLoader classLoader) {
  +        
  +        if (classLoader == null) {
  +            return null;
  +        }
  +        
           ClassLoaderLogInfo info = (ClassLoaderLogInfo) classLoaderLoggers
                   .get(classLoader);
           if (info == null) {
  @@ -330,28 +332,9 @@
                               this.prefix.set(prefix);
                               Handler handler = 
                                   (Handler) classLoader.loadClass(handlerClassName).newInstance();
  -                            // FIXME: The specification strongly implies this should be done in the
  -                            // handler configuration
  -                            /*
  -                            // Initialize handler's level
  -                            String handlerLevel = 
  -                                info.props.getProperty(handlerName + ".level");
  -                            if (handlerLevel != null) {
  -                                handler.setLevel(Level.parse(handlerLevel.trim()));
  -                            }
  -                            // Initialize filter
  -                            String filterName =
  -                                info.props.getProperty(handlerName + ".filter");
  -                            if (filterName != null) {
  -                                try {
  -                                    handler.setFilter
  -                                        ((Filter) classLoader.loadClass(filterName).newInstance());
  -                                } catch (Exception e) {
  -                                    // FIXME: Report this using the main logger ?
  -                                    // Ignore
  -                                }
  -                            }
  -                            */
  +                            // The specification strongly implies all configuration should be done 
  +                            // during the creation of the handler object.
  +                            // This includes setting level, filter, formatter and encoding.
                               this.prefix.set(null);
                               info.handlers.put(handlerName, handler);
                               if (rootHandlers == null) {
  @@ -365,9 +348,9 @@
                       
                       // Add handlers to the root logger, if any are defined using the .handlers property.
                       if (rootHandlers != null) {
  -                        StringTokenizer tok2 = new StringTokenizer(rootHandlers);
  +                        StringTokenizer tok2 = new StringTokenizer(rootHandlers, ",");
                           while (tok2.hasMoreTokens()) {
  -                            String handlerName = (tok2.nextToken());
  +                            String handlerName = (tok2.nextToken().trim());
                               Handler handler = (Handler) info.handlers.get(handlerName);
                               if (handler != null) {
                                   localRootLogger.addHandler(handler);
  
  
  

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