8011638: Remove deprecated methods in sun.util.logging.PlatformLogger
Reviewed-by: psandoz, mchung, alanb, chegar
--- a/jdk/src/share/classes/sun/font/FontUtilities.java Wed Oct 16 15:06:27 2013 +0100
+++ b/jdk/src/share/classes/sun/font/FontUtilities.java Wed Oct 16 17:19:09 2013 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2013, 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
@@ -133,9 +133,9 @@
debugFonts = true;
logger = PlatformLogger.getLogger("sun.java2d");
if (debugLevel.equals("warning")) {
- logger.setLevel(PlatformLogger.WARNING);
+ logger.setLevel(PlatformLogger.Level.WARNING);
} else if (debugLevel.equals("severe")) {
- logger.setLevel(PlatformLogger.SEVERE);
+ logger.setLevel(PlatformLogger.Level.SEVERE);
}
}
--- a/jdk/src/share/classes/sun/util/logging/PlatformLogger.java Wed Oct 16 15:06:27 2013 +0100
+++ b/jdk/src/share/classes/sun/util/logging/PlatformLogger.java Wed Oct 16 17:19:09 2013 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2013, 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
@@ -85,22 +85,18 @@
* @since 1.7
*/
public class PlatformLogger {
- /*
- * These constants should be shortcuts to Level enum constants that
- * the clients of sun.util.logging.PlatformLogger require no source
- * modification and avoid the conversion from int to Level enum.
- *
- * This can be done when JavaFX is converted to use the new PlatformLogger.Level API.
- */
- public static final int OFF = Integer.MAX_VALUE;
- public static final int SEVERE = 1000;
- public static final int WARNING = 900;
- public static final int INFO = 800;
- public static final int CONFIG = 700;
- public static final int FINE = 500;
- public static final int FINER = 400;
- public static final int FINEST = 300;
- public static final int ALL = Integer.MIN_VALUE;
+
+ // The integer values must match that of {@code java.util.logging.Level}
+ // objects.
+ private static final int OFF = Integer.MAX_VALUE;
+ private static final int SEVERE = 1000;
+ private static final int WARNING = 900;
+ private static final int INFO = 800;
+ private static final int CONFIG = 700;
+ private static final int FINE = 500;
+ private static final int FINER = 400;
+ private static final int FINEST = 300;
+ private static final int ALL = Integer.MIN_VALUE;
/**
* PlatformLogger logging levels.
@@ -127,14 +123,14 @@
/* java.util.logging.Level */ Object javaLevel;
// ascending order for binary search matching the list of enum constants
- private static final int[] levelValues = new int[] {
+ private static final int[] LEVEL_VALUES = new int[] {
PlatformLogger.ALL, PlatformLogger.FINEST, PlatformLogger.FINER,
PlatformLogger.FINE, PlatformLogger.CONFIG, PlatformLogger.INFO,
PlatformLogger.WARNING, PlatformLogger.SEVERE, PlatformLogger.OFF
};
public int intValue() {
- return levelValues[this.ordinal()];
+ return LEVEL_VALUES[this.ordinal()];
}
static Level valueOf(int level) {
@@ -153,7 +149,7 @@
}
// return the nearest Level value >= the given level,
// for level > SEVERE, return SEVERE and exclude OFF
- int i = Arrays.binarySearch(levelValues, 0, levelValues.length-2, level);
+ int i = Arrays.binarySearch(LEVEL_VALUES, 0, LEVEL_VALUES.length-2, level);
return values()[i >= 0 ? i : (-i-1)];
}
}
@@ -264,39 +260,6 @@
/**
* Returns true if a message of the given level would actually
* be logged by this logger.
- *
- * @deprecated Use isLoggable(Level) instead.
- */
- @Deprecated
- public boolean isLoggable(int levelValue) {
- return isLoggable(Level.valueOf(levelValue));
- }
-
- /**
- * Gets the current log level. Returns 0 if the current effective level is
- * not set (equivalent to Logger.getLevel() returns null).
- *
- * @deprecated Use level() instead
- */
- @Deprecated
- public int getLevel() {
- Level level = loggerProxy.getLevel();
- return level != null ? level.intValue() : 0;
- }
-
- /**
- * Sets the log level.
- *
- * @deprecated Use setLevel(Level) instead
- */
- @Deprecated
- public void setLevel(int newLevel) {
- loggerProxy.setLevel(newLevel == 0 ? null : Level.valueOf(newLevel));
- }
-
- /**
- * Returns true if a message of the given level would actually
- * be logged by this logger.
*/
public boolean isLoggable(Level level) {
if (level == null) {
--- a/jdk/test/sun/util/logging/PlatformLoggerTest.java Wed Oct 16 15:06:27 2013 +0100
+++ b/jdk/test/sun/util/logging/PlatformLoggerTest.java Wed Oct 16 17:19:09 2013 +0200
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009, 2013, 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
@@ -23,7 +23,7 @@
/*
* @test
- * @bug 6882376 6985460 8010309
+ * @bug 6882376 6985460 8010309 8011638
* @summary Test if java.util.logging.Logger is created before and after
* logging is enabled. Also validate some basic PlatformLogger
* operations. othervm mode to make sure java.util.logging
@@ -34,8 +34,10 @@
*/
import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.logging.*;
import sun.util.logging.PlatformLogger;
+import sun.util.logging.LoggingSupport;
import static sun.util.logging.PlatformLogger.Level.*;
public class PlatformLoggerTest {
@@ -104,17 +106,6 @@
throw new RuntimeException("logger " + logger.getName() + ": " + level +
(expected ? " not loggable" : " loggable"));
}
-
- if (logger.isLoggable(level.intValue()) != expected) {
- throw new RuntimeException("logger " + logger.getName() + ": " + level.intValue() +
- (expected ? " not loggable" : " loggable"));
- }
-
- int value = level.intValue() + 5; // custom level value
- if (expected && !logger.isLoggable(value)) {
- throw new RuntimeException("logger " + logger.getName() + ": " + value +
- " not loggable");
- }
}
private static void checkLevel(PlatformLogger logger, PlatformLogger.Level level) {
@@ -122,11 +113,6 @@
throw new RuntimeException("Invalid level for logger " +
logger.getName() + ": " + logger.level() + " != " + level);
}
-
- if (logger.getLevel() != level.intValue()) {
- throw new RuntimeException("Invalid level for logger " +
- logger.getName() + ": " + logger.getLevel() + " != " + level.intValue());
- }
}
private static void checkLogger(String name, Level level) {
@@ -177,6 +163,11 @@
checkLoggerLevel(logger, Level.ALL);
}
}
+
+ Logger javaLogger = Logger.getLogger("foo.bar.baz");
+ for (Level level : levels) {
+ checkJavaLoggerLevel(javaLogger, level);
+ }
}
private static void checkLoggerLevel(PlatformLogger logger, Level level) {
@@ -196,6 +187,50 @@
}
}
+ private static void checkJavaLoggerLevel(Logger logger, Level level) {
+ // This method exercise the mapping of java level to platform level
+ // when the java level is not one of the standard levels...
+
+ System.out.println("Testing Java Level with: " + level.getName());
+
+ // create a brand new java logger
+ Logger javaLogger = (Logger) LoggingSupport.getLogger(logger.getName()+"."+level.getName());
+
+ // Set a non standard java.util.logging.Level on the java logger
+ // (except for OFF & ALL - which will remain unchanged)
+ int intValue = level.intValue();
+ if (level != Level.ALL && level != Level.OFF) {
+ intValue -= 7;
+ }
+ javaLogger.setLevel(Level.parse(String.valueOf(intValue)));
+
+ // check the level set in java.util.logging.Logger
+ Level effectiveLevel = javaLogger.getLevel();
+ System.out.println("Effective Java Level used is: " + effectiveLevel);
+
+ if (effectiveLevel.intValue() != intValue) {
+ throw new RuntimeException("Retrieved backing java.util.logging.Logger level.intValue() "
+ + effectiveLevel.intValue() + " is not the expected " + intValue);
+ }
+ if (intValue != level.intValue() && javaLogger.getLevel() == level) {
+ throw new RuntimeException("Retrieved backing java.util.logging.Logger level "
+ + effectiveLevel + " is " + level);
+ }
+ if (intValue == level.intValue() && javaLogger.getLevel() != level) {
+ throw new RuntimeException("Retrieved backing java.util.logging.Logger level "
+ + effectiveLevel + " is not " + level);
+ }
+
+ // check the level set in the PlatformLogger
+ PlatformLogger plogger = PlatformLogger.getLogger(javaLogger.getName());
+ PlatformLogger.Level expected = PlatformLogger.Level.valueOf(level.getName());
+ if (plogger.level() != expected) {
+ throw new RuntimeException("Retrieved backing PlatformLogger level "
+ + plogger.level() + " is not the expected " + expected);
+
+ }
+ }
+
private static void checkPlatformLoggerLevelMapping(Level level) {
// map the given level to PlatformLogger.Level of the same name and value
PlatformLogger.Level platformLevel = PlatformLogger.Level.valueOf(level.getName());
@@ -203,26 +238,10 @@
throw new RuntimeException("Mismatched level: " + level
+ " PlatformLogger.Level" + platformLevel);
}
-
- try {
- // validate if there is a public static final field in PlatformLogger
- Field constantField = PlatformLogger.class.getField(level.getName());
- int l = (int) constantField.get(null);
- if (l != platformLevel.intValue()) {
- throw new RuntimeException("static final " + level.getName() + " (" +
- l + ") != " + platformLevel.intValue());
- }
- } catch (Exception e) {
- throw new RuntimeException("No public static PlatformLogger." + level.getName() +
- " field", e);
- }
- if (!platformLevel.name().equals(level.getName()))
+ if (!platformLevel.name().equals(level.getName())) {
throw new RuntimeException("The value of PlatformLogger." + level.getName() + ".name() is "
+ platformLevel.name() + " but expected " + level.getName());
-
- if (platformLevel.intValue() != level.intValue())
- throw new RuntimeException("The value of PlatformLogger." + level.intValue() + ".intValue() is "
- + platformLevel.intValue() + " but expected " + level.intValue());
+ }
}
static Point[] getPoints() {