harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r450019 - in /incubator/harmony/enhanced/classlib/trunk/modules/logging/src: main/java/java/util/logging/ main/java/org/apache/harmony/logging/internal/nls/ test/java/org/apache/harmony/logging/tests/java/util/logging/
Date Tue, 26 Sep 2006 12:22:17 GMT
Author: pyang
Date: Tue Sep 26 05:22:16 2006
New Revision: 450019

URL: http://svn.apache.org/viewvc?view=rev&rev=450019
Log:
More bug fixing and refactory:
1. fix bug of LogManager initialization if j.u.l.config.class property is specified
2. tidy up LogManager, remove unnecessary private method
3. fix compiler warning
4. i18n messages update

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java?view=diff&rev=450019&r1=450018&r2=450019
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/ErrorManager.java
Tue Sep 26 05:22:16 2006
@@ -58,6 +58,7 @@
      */
     public static final int FORMAT_FAILURE = 5;
 
+    @SuppressWarnings("nls")
     private static final String[] FAILURES = new String[] { "GENERIC_FAILURE",
             "WRITE_FAILURE", "FLUSH_FAILURE", "CLOSE_FAILURE", "OPEN_FAILURE",
             "FORMAT_FAILURE" };

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java?view=diff&rev=450019&r1=450018&r2=450019
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/FileHandler.java
Tue Sep 26 05:22:16 2006
@@ -101,7 +101,7 @@
  */
 public class FileHandler extends StreamHandler {
 
-    private static final String LCK_EXT = ".lck";
+    private static final String LCK_EXT = ".lck"; //$NON-NLS-1$
 
     /*
      * ---------------------------------------------

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java?view=diff&rev=450019&r1=450018&r2=450019
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Level.java
Tue Sep 26 05:22:16 2006
@@ -47,47 +47,47 @@
     /**
      * The OFF level provides no logging messages.
      */
-    public static final Level OFF = new Level("OFF", Integer.MAX_VALUE);
+    public static final Level OFF = new Level("OFF", Integer.MAX_VALUE); //$NON-NLS-1$
 
     /**
      * The SEVERE level indicates a severe failure.
      */
-    public static final Level SEVERE = new Level("SEVERE", 1000);
+    public static final Level SEVERE = new Level("SEVERE", 1000); //$NON-NLS-1$
 
     /**
      * The WARNING level indicates a warning.
      */
-    public static final Level WARNING = new Level("WARNING", 900);
+    public static final Level WARNING = new Level("WARNING", 900); //$NON-NLS-1$
 
     /**
      * The INFO level indicates an informative message.
      */
-    public static final Level INFO = new Level("INFO", 800);
+    public static final Level INFO = new Level("INFO", 800); //$NON-NLS-1$
 
     /**
      * The CONFIG level indicates a static configuration message.
      */
-    public static final Level CONFIG = new Level("CONFIG", 700);
+    public static final Level CONFIG = new Level("CONFIG", 700); //$NON-NLS-1$
 
     /**
      * The FINE level provides tracing messages.
      */
-    public static final Level FINE = new Level("FINE", 500);
+    public static final Level FINE = new Level("FINE", 500); //$NON-NLS-1$
 
     /**
      * The FINER level provides more detailed tracing messages.
      */
-    public static final Level FINER = new Level("FINER", 400);
+    public static final Level FINER = new Level("FINER", 400); //$NON-NLS-1$
 
     /**
      * The FINEST level provides highly detailed tracing messages.
      */
-    public static final Level FINEST = new Level("FINEST", 300);
+    public static final Level FINEST = new Level("FINEST", 300); //$NON-NLS-1$
 
     /**
      * The ALL level provides all logging messages.
      */
-    public static final Level ALL = new Level("ALL", Integer.MIN_VALUE);
+    public static final Level ALL = new Level("ALL", Integer.MIN_VALUE); //$NON-NLS-1$
 
     /**
      * Parses a level name into a <code>Level</code> object.

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java?view=diff&rev=450019&r1=450018&r2=450019
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
Tue Sep 26 05:22:16 2006
@@ -198,6 +198,7 @@
 
 				// if global logger has been initialized, set root as its parent
                 Logger root = new Logger("", null); //$NON-NLS-1$
+                root.setLevel(Level.INFO);
                 Logger.global.setParent(root);
                 
                 manager.addLogger(root);
@@ -299,7 +300,12 @@
         String parentName = name;
         while ((lastSeparator = parentName.lastIndexOf('.')) != -1) {
             parentName = parentName.substring(0, lastSeparator);
-            if ((parent = loggers.get(parentName)) != null) {
+            parent = loggers.get(parentName);
+            if (parent != null) {
+                logger.internalSetParent(parent);
+                break;
+            }else if(getProperty(parentName+".level") != null || getProperty(parentName+".handlers")
!= null){//$NON-NLS-1$ //$NON-NLS-2$
+                parent = Logger.getLogger(parentName);
                 logger.internalSetParent(parent);
                 break;
             }
@@ -309,6 +315,7 @@
         }
 
         // find children
+        //TODO: performance can be improved here?
         Collection<Logger> allLoggers = loggers.values();
         for (Logger child : allLoggers) {
             Logger oldParent = child.getParent();
@@ -378,7 +385,30 @@
      *             not have the required permissions to perform this action
      */
     public void readConfiguration() throws IOException {
-        readConfigurationImpl();
+        checkAccess();
+        // check config class
+        String configClassName = System.getProperty("java.util.logging.config.class"); //$NON-NLS-1$
+        if (null == configClassName || null == getInstanceByClass(configClassName)) {
+            // if config class failed, check config file       
+            String configFile = System.getProperty("java.util.logging.config.file"); //$NON-NLS-1$
+            if (null == configFile) {
+                // if cannot find configFile, use default logging.properties
+                configFile = new StringBuilder().append(
+                        System.getProperty("java.home")).append(File.separator) //$NON-NLS-1$
+                        .append("lib").append(File.separator).append( //$NON-NLS-1$
+                                "logging.properties").toString(); //$NON-NLS-1$
+            }
+            InputStream input = null;
+            try {
+                input = new BufferedInputStream(new FileInputStream(configFile));
+                readConfigurationImpl(input);
+            } finally {
+                try {
+                    input.close();
+                } catch (Exception e) {// ignore
+                }
+            }
+        }
     }
 
     // use privilege code to get system property
@@ -402,8 +432,8 @@
                         className);
                 return clazz.newInstance();
             } catch (Exception innerE) {
-                //logging.20=Logging configuration class "{0}" failed
-                System.err.println(Messages.getString("logging.20", className));
+                //logging.20=Loading class "{0}" failed
+                System.err.println(Messages.getString("logging.20", className)); //$NON-NLS-1$
                 System.err.println(innerE);
                 return null;
             }
@@ -411,80 +441,13 @@
 
     }
 
-    // actual default initialization process
-    private synchronized void readConfigurationImpl() throws IOException {
-        checkAccess();
-        boolean needInit = true;
-
-        // check config class
-        String configClassName = System.getProperty("java.util.logging.config.class"); //$NON-NLS-1$
-        if (null != configClassName) {
-            if (null == getInstanceByClass(configClassName)) {
-                return;
-            }
-            needInit = false;
-        }
-        // if config class failed, check config file
-        if (needInit) {
-            String configFile = System.getProperty("java.util.logging.config.file"); //$NON-NLS-1$
-            if (null == configFile) {
-                // if cannot find configFile, use default logging.properties
-                configFile = new StringBuilder().append(
-                        System.getProperty("java.home")).append(File.separator) //$NON-NLS-1$
-                        .append("lib").append(File.separator).append( //$NON-NLS-1$
-                                "logging.properties").toString(); //$NON-NLS-1$
-            }
-            InputStream input = null;
-            try {
-                input = new BufferedInputStream(new FileInputStream(configFile));
-                readConfigurationImpl(input);
-            } finally {
-                try {
-                    input.close();
-                } catch (Exception e) {// ignore
-                }
-            }
-        }
-    }
-
     // actual initialization process from a given input stream
     private synchronized void readConfigurationImpl(InputStream ins)
             throws IOException {
         reset();
         props.load(ins);
-
-        // configs
-        parseConfigProp();
-
-        // set levels for logger
-        initLoggers();
-        listeners.firePropertyChange(null, null, null);
-    }
-
-    // init "level" properties for all registered loggers
-    private void initLoggers() {
-        Enumeration<?> enumeration = props.propertyNames();
-        while (enumeration.hasMoreElements()) {
-            // search for all properties whose name is ended with ".level"
-            String property = (String) enumeration.nextElement();
-            if (property.endsWith(".level")) { //$NON-NLS-1$
-                String loggerName = property.substring(0,
-                        property.length() - ".level".length()); //$NON-NLS-1$
-                Logger l = loggers.get(loggerName);
-                if (null != l) {
-                    l.setManager(this);
-                }
-            }else if(property.endsWith(".handlers")){ //$NON-NLS-1$
-                String loggerName = property.substring(0,
-                        property.length() - ".handlers".length()); //$NON-NLS-1$
-                Logger.getLogger(loggerName);
-                //lazily load handlers because some of them are expensive
-            }
-        }
-    }
-
-    // parse property "config" and apply setting
-    private void parseConfigProp() {
+        
+        // parse property "config" and apply setting
         String configs = props.getProperty("config"); //$NON-NLS-1$
         if (null != configs) {
             StringTokenizer st = new StringTokenizer(configs, " "); //$NON-NLS-1$
@@ -493,7 +456,18 @@
                 getInstanceByClass(configerName);
             }
         }
+        
+        // set levels for logger
+        Collection<Logger> allLoggers = loggers.values();
+        for(Logger logger : allLoggers){
+            String property = props.getProperty(logger.getName()+".level"); //$NON-NLS-1$
+            if(null != property){
+                logger.setLevel(Level.parse(property));
+            }
+        }
+        listeners.firePropertyChange(null, null, null);
     }
+
 
     /**
      * Re-initialize the properties and configuration from the given

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java?view=diff&rev=450019&r1=450018&r2=450019
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/Logger.java
Tue Sep 26 05:22:16 2006
@@ -515,9 +515,7 @@
         if (this.isNamed) {
             LogManager.getLogManager().checkAccess();
         }
-        LogManager lm = LogManager.getLogManager();
-
-        synchronized (lm) {
+        synchronized (LogManager.getLogManager()) {
             setLevelImpl(newLevel);
         }
     }
@@ -708,7 +706,7 @@
      */
     public void entering(String sourceClass, String sourceMethod) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, "ENTRY");
+            LogRecord record = new LogRecord(Level.FINER, "ENTRY"); //$NON-NLS-1$
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -732,7 +730,7 @@
      */
     public void entering(String sourceClass, String sourceMethod, Object param) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, "ENTRY" + " {0}"); //$NON-NLS-1$
+            LogRecord record = new LogRecord(Level.FINER, "ENTRY" + " {0}"); //$NON-NLS-1$
//$NON-NLS-2$
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -758,9 +756,9 @@
     public void entering(String sourceClass, String sourceMethod,
             Object[] params) {
         if (internalIsLoggable(Level.FINER)) {
-        	String msg = "ENTRY";
+        	String msg = "ENTRY"; //$NON-NLS-1$
 			if (null != params) {
-				StringBuilder msgBuffer = new StringBuilder("ENTRY");
+				StringBuilder msgBuffer = new StringBuilder("ENTRY"); //$NON-NLS-1$
 				for (int i = 0; i < params.length; i++) {
 					msgBuffer.append(" {" + i + "}"); //$NON-NLS-1$ //$NON-NLS-2$
 				}
@@ -788,7 +786,7 @@
      */
     public void exiting(String sourceClass, String sourceMethod) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, "RETURN");
+            LogRecord record = new LogRecord(Level.FINER, "RETURN"); //$NON-NLS-1$
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -812,7 +810,7 @@
      */
     public void exiting(String sourceClass, String sourceMethod, Object result) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, "RETURN" + " {0}"); //$NON-NLS-1$
+            LogRecord record = new LogRecord(Level.FINER, "RETURN" + " {0}"); //$NON-NLS-1$
//$NON-NLS-2$
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);
@@ -838,7 +836,7 @@
     public void throwing(String sourceClass, String sourceMethod,
             Throwable thrown) {
         if (internalIsLoggable(Level.FINER)) {
-            LogRecord record = new LogRecord(Level.FINER, "THROW");
+            LogRecord record = new LogRecord(Level.FINER, "THROW"); //$NON-NLS-1$
             record.setLoggerName(this.name);
             record.setSourceClassName(sourceClass);
             record.setSourceMethodName(sourceMethod);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties?view=diff&rev=450019&r1=450018&r2=450019
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
Tue Sep 26 05:22:16 2006
@@ -33,7 +33,7 @@
 logging.1E=Error message - {0}
 logging.1F=Exception - {0}
 logging.2=The OutputStream parameter is null
-logging.20=Logging configuration class "{0}" failed
+logging.20=Loading class "{0}" failed
 logging.3=The Formatter parameter is null.
 logging.4=The 'level' parameter is null.
 logging.5=Different version - {0}.{1}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java?view=diff&rev=450019&r1=450018&r2=450019
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java
Tue Sep 26 05:22:16 2006
@@ -19,6 +19,7 @@
 import java.beans.PropertyChangeListener;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintStream;
 import java.security.Permission;
 import java.util.Enumeration;
 import java.util.Properties;
@@ -32,6 +33,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream;
 import org.apache.harmony.logging.tests.java.util.logging.util.EnvironmentHelper;
 
 /**
@@ -74,11 +76,11 @@
 		mockManager = new MockLogManager();
 		listener = new MockPropertyChangeListener();
 		handler = new MockHandler();
-		initProps();
+		props = initProps();
 	}
 
-	private void initProps() throws Exception {
-		props = new Properties();
+	static Properties initProps() throws Exception {
+		Properties props = new Properties();
 		props.put("handlers", className + "$MockHandler " + className
 				+ "$MockHandler");
 		props.put("java.util.logging.FileHandler.pattern", "%h/java%u.log");
@@ -92,6 +94,7 @@
 				"java.util.logging.SimpleFormatter");
 		props.put("LogManagerTestFoo.handlers", "java.util.logging.ConsoleHandler");
 		props.put("LogManagerTestFoo.level", "WARNING");
+        return props;
 	}
 
 	/*
@@ -675,91 +678,133 @@
 	}
 
 	public void testGlobalPropertyConfig() throws Exception {
-		// before add config property, root has two handler
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(2, manager.getLogger("").getHandlers().length);
-
-		// one valid config class
-		props.setProperty("config", className + "$MockValidConfig");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(3, manager.getLogger("").getHandlers().length);
-
-		// two config class take effect orderly
-		props.setProperty("config", className + "$MockValidConfig " + className
-				+ "$MockValidConfig2");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(2, manager.getLogger("").getHandlers().length);
-
-		props.setProperty("config", className + "$MockValidConfig2 "
-				+ className + "$MockValidConfig");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(3, manager.getLogger("").getHandlers().length);
-
-		// invalid config class which throw exception, just pring exception and
-		// message
-		props.setProperty("config", className + "$MockInvalidConfigException");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-
-		// invalid config class without default constructor, just pring
-		// exception and message
-		props.setProperty("config", className
-				+ "$MockInvalidConfigNoDefaultConstructor");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-
-		// bad config class name, just print exception and message
-		props.setProperty("config", "badname");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-
-		// invalid separator, nothing happened
-		props.setProperty("config", className + "$MockValidConfig2;"
-				+ className + "$MockValidConfig");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(2, manager.getLogger("").getHandlers().length);
-		props.setProperty("config", className + "$MockValidConfig2;"
-				+ className + "$MockValidConfig " + className
-				+ "$MockValidConfig");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(3, manager.getLogger("").getHandlers().length);
-
-		// duplicate config class, take effect twice
-		props.setProperty("config", className + "$MockValidConfig " + className
-				+ "$MockValidConfig");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(4, manager.getLogger("").getHandlers().length);
-
-		// invalid config classes mixed with valid config classes, valid config
-		// classes take effect
-		props.setProperty("config", "badname " + className
-				+ "$MockValidConfig " + className
-				+ "$MockInvalidConfigNoDefaultConstructor " + className
-				+ "$MockValidConfig");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(4, manager.getLogger("").getHandlers().length);
-
-		// global property take effect before logger specified property
-		props.setProperty("config", className + "$MockValidConfig");
-		manager.readConfiguration(EnvironmentHelper
-				.PropertiesToInputStream(props));
-		assertEquals(Level.FINE, manager.getLogger("").getLevel());
-
-	}
-
+        PrintStream err = System.err;
+        try {
+            System.setErr(new PrintStream(new NullOutputStream()));
+            // before add config property, root has two handler
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(2, manager.getLogger("").getHandlers().length);
+
+            // one valid config class
+            props.setProperty("config", className + "$MockValidConfig");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(3, manager.getLogger("").getHandlers().length);
+
+            // two config class take effect orderly
+            props.setProperty("config", className + "$MockValidConfig "
+                    + className + "$MockValidConfig2");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(2, manager.getLogger("").getHandlers().length);
+
+            props.setProperty("config", className + "$MockValidConfig2 "
+                    + className + "$MockValidConfig");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(3, manager.getLogger("").getHandlers().length);
+
+            // invalid config class which throw exception, just pring exception
+            // and
+            // message
+            props.setProperty("config", className
+                    + "$MockInvalidConfigException");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+
+            // invalid config class without default constructor, just pring
+            // exception and message
+            props.setProperty("config", className
+                    + "$MockInvalidConfigNoDefaultConstructor");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+
+            // bad config class name, just print exception and message
+            props.setProperty("config", "badname");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+
+            // invalid separator, nothing happened
+            props.setProperty("config", className + "$MockValidConfig2;"
+                    + className + "$MockValidConfig");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(2, manager.getLogger("").getHandlers().length);
+            props.setProperty("config", className + "$MockValidConfig2;"
+                    + className + "$MockValidConfig " + className
+                    + "$MockValidConfig");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(3, manager.getLogger("").getHandlers().length);
+
+            // duplicate config class, take effect twice
+            props.setProperty("config", className + "$MockValidConfig "
+                    + className + "$MockValidConfig");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(4, manager.getLogger("").getHandlers().length);
+
+            // invalid config classes mixed with valid config classes, valid
+            // config
+            // classes take effect
+            props.setProperty("config", "badname " + className
+                    + "$MockValidConfig " + className
+                    + "$MockInvalidConfigNoDefaultConstructor " + className
+                    + "$MockValidConfig");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(4, manager.getLogger("").getHandlers().length);
+
+            // global property take effect before logger specified property
+            props.setProperty("config", className + "$MockValidConfig");
+            manager.readConfiguration(EnvironmentHelper
+                    .PropertiesToInputStream(props));
+            assertEquals(Level.FINE, manager.getLogger("").getLevel());
+        } finally {
+            System.setErr(err);
+        }
 
+    }
+    
+    public void testValidConfigClass() throws Exception{
+        String oldProperty = System.getProperty("java.util.logging.config.class");
+        try{
+//            System.setProperty("java.util.logging.config.class", "org.apache.harmony.logging.tests.java.util.logging.LogManagerTest$ConfigClass");
+            System.setProperty("java.util.logging.config.class", this.getClass().getName()+"$ConfigClass");
           
+            assertNull(manager.getLogger("testConfigClass.foo"));
+            
+            manager.readConfiguration();
+            assertNull(manager.getLogger("testConfigClass.foo"));
+            Logger l = Logger.getLogger("testConfigClass.foo.child");
+            assertSame(Level.FINEST, manager.getLogger("").getLevel());
+            assertEquals(0, manager.getLogger("").getHandlers().length);            
+            assertEquals("testConfigClass.foo", l.getParent().getName());
+        }finally{
+            if(oldProperty != null){
+                System.setProperty("java.util.logging.config.class", oldProperty);
+            }
+        }
+    }
+    
 	/*
-	 * ---------------------------------------------------- mock classes
+	 * ---------------------------------------------------- 
+     * mock classes
 	 * ----------------------------------------------------
 	 */
+    public static class ConfigClass {
+        public ConfigClass() throws Exception{
+            LogManager man = LogManager.getLogManager();
+            Properties props = LogManagerTest.initProps();
+            props.put("testConfigClass.foo.level", "OFF");
+            props.put("testConfigClass.foo.handlers", "java.util.logging.ConsoleHandler");
       
+            props.put(".level", "FINEST");
+            props.remove("handlers");
+            InputStream in = EnvironmentHelper.PropertiesToInputStream(props);
+            man.readConfiguration(in);
+        }
+    }
+    
 	public static class MockInvalidInitClass {
 		public MockInvalidInitClass() {
 			throw new RuntimeException();



Mime
View raw message