8211093: Default logging.properties sets log level for com.xyz.foo
authordfuchs
Thu, 13 Dec 2018 11:27:37 +0000
changeset 53009 c45615dc6bfc
parent 53008 9a73a4e4011f
child 53010 086dfcfc3731
8211093: Default logging.properties sets log level for com.xyz.foo Reviewed-by: bpb, rriggs
src/java.logging/share/conf/logging.properties
test/jdk/java/util/logging/DefaultConfigTest.java
--- a/src/java.logging/share/conf/logging.properties	Thu Dec 13 15:11:25 2018 +0530
+++ b/src/java.logging/share/conf/logging.properties	Thu Dec 13 11:27:37 2018 +0000
@@ -60,4 +60,4 @@
 
 # For example, set the com.xyz.foo logger to only log SEVERE
 # messages:
-com.xyz.foo.level = SEVERE
+# com.xyz.foo.level = SEVERE
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/logging/DefaultConfigTest.java	Thu Dec 13 11:27:37 2018 +0000
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8211093
+ * @summary Check default configuration
+ * @build DefaultConfigTest
+ * @run main/othervm DefaultConfigTest
+ */
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+public class DefaultConfigTest {
+    static final java.io.PrintStream out = System.out;
+    public static void main(String arg[]) {
+        LogManager manager = LogManager.getLogManager();
+
+        if (!Set.of(Collections.list(manager.getLoggerNames()).toArray())
+                .equals(Set.of("", "global"))) {
+            throw new RuntimeException("Unexpected logger name in: "
+                    + Collections.list(manager.getLoggerNames()));
+        }
+        Logger global = Logger.getGlobal();
+        Logger root = Logger.getLogger("");
+        Logger foo  = Logger.getLogger("com.xyz.foo");
+        if (!Set.of(Collections.list(manager.getLoggerNames()).toArray())
+                .equals(Set.of("", "global", "com.xyz.foo"))) {
+            throw new RuntimeException("Unexpected logger name in: "
+                    + Collections.list(manager.getLoggerNames()));
+        }
+        for (Logger l : List.of(global, foo)) {
+            if (l.getLevel() != null) {
+                throw new RuntimeException("Unexpected level "
+                        + l.getLevel() + " for " + l.getName());
+            }
+            if (l.getHandlers().length != 0) {
+                throw new RuntimeException("Unexpected handlers "
+                        + List.of(l.getHandlers()) + " for " + l.getName());
+            }
+            for (Level level : List.of(
+                    Level.ALL, Level.FINEST, Level.FINER, Level.FINE, Level.CONFIG)) {
+                if (l.isLoggable(level)) {
+                    throw new RuntimeException("Level "
+                            + level + " should not be loggable for " + l.getName());
+                }
+            }
+            for (Level level : List.of(
+                    Level.INFO, Level.WARNING, Level.SEVERE)) {
+                if (!l.isLoggable(level)) {
+                    throw new RuntimeException("Level "
+                            + level + " should be loggable for " + l.getName());
+                }
+            }
+        }
+        if (root.getLevel() != Level.INFO) {
+            throw new RuntimeException("Unexpected level "
+                    + root.getLevel() + " for root logger");
+        }
+        if (root.getHandlers().length != 1) {
+            throw new RuntimeException("Unexpected handlers "
+                    + List.of(root.getHandlers()) + " for root logger");
+        }
+        if (root.getHandlers()[0].getClass() != ConsoleHandler.class) {
+            throw new RuntimeException("Unexpected handlers "
+                    + List.of(root.getHandlers()) + " for root logger");
+        }
+        if (root.getHandlers()[0].getLevel() != Level.INFO) {
+            throw new RuntimeException("Unexpected level "
+                    + root.getHandlers()[0].getLevel() + " for handler "
+                    + root.getHandlers()[0]);
+        }
+        out.println(List.of(root, global, foo).stream()
+                .map(Logger::getName)
+                .map(s -> String.format("\"%s\"", s))
+                .collect(Collectors.joining(", ",
+                        "Default configuration checked for ",
+                        ".")));
+    }
+}