提交 11a3c1ee 编写于 作者: M mchung

6882376: Add internal support for JRE implementation to eliminate the dependency on logging

Summary: Added sun.util.logging.PlatformLogger for JRE implementation to log messages.
Reviewed-by: alanb, naoto
上级 14f93216
......@@ -31,7 +31,7 @@ include $(BUILDDIR)/common/Defs.gmk
#
# Files to compile.
#
AUTO_FILES_JAVA_DIRS = java/util/logging
AUTO_FILES_JAVA_DIRS = java/util/logging sun/util/logging
#
# Resources
......@@ -46,7 +46,6 @@ RESOURCE_BUNDLES_COMPILED_PROPERTIES = \
include $(BUILDDIR)/common/Classes.gmk
properties: $(LIBDIR)/logging.properties
$(LIBDIR)/logging.properties: $(SHARE_SRC)/lib/logging.properties
$(install-file)
......
......@@ -35,12 +35,12 @@ import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.spi.CurrencyNameProvider;
import java.util.spi.LocaleServiceProvider;
import sun.util.LocaleServiceProviderPool;
import sun.util.logging.PlatformLogger;
import sun.util.resources.LocaleData;
import sun.util.resources.OpenListResourceBundle;
......@@ -244,7 +244,7 @@ public final class Currency implements Serializable {
}
}
} catch (IOException e) {
log(Level.INFO, "currency.properties is ignored because of an IOException", e);
info("currency.properties is ignored because of an IOException", e);
}
return null;
}
......@@ -686,7 +686,7 @@ public final class Currency implements Serializable {
.append("The entry in currency.properties for ")
.append(ctry).append(" is ignored because of the invalid country code.")
.toString();
log(Level.INFO, message, null);
info(message, null);
return;
}
......@@ -698,7 +698,7 @@ public final class Currency implements Serializable {
.append(ctry)
.append(" is ignored because the value format is not recognized.")
.toString();
log(Level.INFO, message, null);
info(message, null);
return;
}
......@@ -726,13 +726,13 @@ public final class Currency implements Serializable {
setMainTableEntry(ctry.charAt(0), ctry.charAt(1), entry);
}
private static void log(Level level, String message, Throwable t) {
Logger logger = Logger.getLogger("java.util.Currency");
if (logger.isLoggable(level)) {
private static void info(String message, Throwable t) {
PlatformLogger logger = PlatformLogger.getLogger("java.util.Currency");
if (logger.isLoggable(PlatformLogger.INFO)) {
if (t != null) {
logger.log(level, message, t);
logger.info(message, t);
} else {
logger.log(level, message);
logger.info(message);
}
}
}
......
......@@ -34,7 +34,7 @@ import java.util.Set;
import java.util.Collection;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.logging.Logger;
import sun.util.logging.PlatformLogger;
import java.util.Comparator;
import sun.misc.ASCIICaseInsensitiveComparator;
......@@ -419,7 +419,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
}
try {
if ((putValue(name, value) != null) && (!lineContinued)) {
Logger.getLogger("java.util.jar").warning(
PlatformLogger.getLogger("java.util.jar").warning(
"Duplicate name in Manifest: " + name
+ ".\n"
+ "Ensure that the manifest does not "
......
......@@ -283,6 +283,10 @@ public class LogManager {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception {
readConfiguration();
// Platform loggers begin to delegate to java.util.logging.Logger
sun.util.logging.PlatformLogger.redirectPlatformLoggers();
return null;
}
});
......
......@@ -530,6 +530,7 @@ public class LogRecord implements java.io.Serializable {
int depth = access.getStackTraceDepth(throwable);
String logClassName = "java.util.logging.Logger";
String plogClassName = "sun.util.logging.PlatformLogger";
boolean lookingForLogger = true;
for (int ix = 0; ix < depth; ix++) {
// Calling getStackTraceElement directly prevents the VM
......@@ -539,15 +540,18 @@ public class LogRecord implements java.io.Serializable {
String cname = frame.getClassName();
if (lookingForLogger) {
// Skip all frames until we have found the first logger frame.
if (cname.equals(logClassName)) {
if (cname.equals(logClassName) || cname.startsWith(plogClassName)) {
lookingForLogger = false;
}
} else {
if (!cname.equals(logClassName)) {
// We've found the relevant frame.
setSourceClassName(cname);
setSourceMethodName(frame.getMethodName());
return;
if (!cname.equals(logClassName) && !cname.startsWith(plogClassName)) {
// skip reflection call
if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
// We've found the relevant frame.
setSourceClassName(cname);
setSourceMethodName(frame.getMethodName());
return;
}
}
}
}
......
......@@ -39,8 +39,8 @@ import java.util.ServiceLoader;
import java.util.ServiceConfigurationError;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import java.util.spi.LocaleServiceProvider;
import sun.util.logging.PlatformLogger;
import sun.util.resources.LocaleData;
import sun.util.resources.OpenListResourceBundle;
......@@ -122,10 +122,15 @@ public final class LocaleServiceProviderPool {
}
});
} catch (PrivilegedActionException e) {
Logger.getLogger("sun.util.LocaleServiceProviderPool").config(e.toString());
config(e.toString());
}
}
private static void config(String message) {
PlatformLogger logger = PlatformLogger.getLogger("sun.util.LocaleServiceProviderPool");
logger.config(message);
}
/**
* Lazy loaded set of available locales.
* Loading all locales is a very long operation.
......@@ -337,7 +342,7 @@ public final class LocaleServiceProviderPool {
if (providersObj != null) {
return providersObj;
} else if (isObjectProvider) {
Logger.getLogger("sun.util.LocaleServiceProviderPool").config(
config(
"A locale sensitive service provider returned null for a localized objects, which should not happen. provider: " + lsp + " locale: " + requested);
}
}
......
此差异已折叠。
......@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.io.ByteArrayOutputStream;
import java.util.logging.Logger;
import sun.util.logging.PlatformLogger;
/**
* Windows registry based implementation of <tt>Preferences</tt>.
......@@ -48,7 +48,7 @@ class WindowsPreferences extends AbstractPreferences{
/**
* Logger for error messages
*/
private static Logger logger;
private static PlatformLogger logger;
/**
* Windows registry path to <tt>Preferences</tt>'s root nodes.
......@@ -1102,9 +1102,9 @@ class WindowsPreferences extends AbstractPreferences{
// assert false;
}
private static synchronized Logger logger() {
private static synchronized PlatformLogger logger() {
if (logger == null) {
logger = Logger.getLogger("java.util.prefs");
logger = PlatformLogger.getLogger("java.util.prefs");
}
return logger;
}
......
/*
* Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6882376
* @summary Test if java.util.logging.Logger is created before and after
* logging is enabled. Also validate some basic PlatformLogger
* operations.
*
* @build PlatformLoggerTest
* @run main PlatformLoggerTest
*/
import java.util.logging.*;
import sun.util.logging.PlatformLogger;
public class PlatformLoggerTest {
private static final int defaultEffectiveLevel = 0;
public static void main(String[] args) throws Exception {
final String FOO_PLATFORM_LOGGER = "test.platformlogger.foo";
final String BAR_PLATFORM_LOGGER = "test.platformlogger.bar";
final String GOO_PLATFORM_LOGGER = "test.platformlogger.goo";
final String BAR_LOGGER = "test.logger.bar";
PlatformLogger goo = PlatformLogger.getLogger(GOO_PLATFORM_LOGGER);
// Create a platform logger using the default
PlatformLogger foo = PlatformLogger.getLogger(FOO_PLATFORM_LOGGER);
checkPlatformLogger(foo, FOO_PLATFORM_LOGGER);
// create a java.util.logging.Logger
// now java.util.logging.Logger should be created for each platform logger
Logger logger = Logger.getLogger(BAR_LOGGER);
logger.setLevel(Level.WARNING);
PlatformLogger bar = PlatformLogger.getLogger(BAR_PLATFORM_LOGGER);
checkPlatformLogger(bar, BAR_PLATFORM_LOGGER);
checkLogger(FOO_PLATFORM_LOGGER, Level.FINER);
checkLogger(BAR_PLATFORM_LOGGER, Level.FINER);
checkLogger(GOO_PLATFORM_LOGGER, null);
checkLogger(BAR_LOGGER, Level.WARNING);
foo.setLevel(PlatformLogger.SEVERE);
checkLogger(FOO_PLATFORM_LOGGER, Level.SEVERE);
}
private static void checkPlatformLogger(PlatformLogger logger, String name) {
if (!logger.getName().equals(name)) {
throw new RuntimeException("Invalid logger's name " +
logger.getName() + " but expected " + name);
}
if (logger.getLevel() != defaultEffectiveLevel) {
throw new RuntimeException("Invalid default level for logger " +
logger.getName());
}
if (logger.isLoggable(PlatformLogger.FINE) != false) {
throw new RuntimeException("isLoggerable(FINE) returns true for logger " +
logger.getName() + " but expected false");
}
logger.setLevel(PlatformLogger.FINER);
if (logger.getLevel() != Level.FINER.intValue()) {
throw new RuntimeException("Invalid level for logger " +
logger.getName() + " " + logger.getLevel());
}
if (logger.isLoggable(PlatformLogger.FINE) != true) {
throw new RuntimeException("isLoggerable(FINE) returns false for logger " +
logger.getName() + " but expected true");
}
logger.info("OK: Testing log message");
}
private static void checkLogger(String name, Level level) {
Logger logger = LogManager.getLogManager().getLogger(name);
if (logger == null) {
throw new RuntimeException("Logger " + name +
" does not exist");
}
if (logger.getLevel() != level) {
throw new RuntimeException("Invalid level for logger " +
logger.getName() + " " + logger.getLevel());
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册