/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
/**
* Platform logger provides an API for the JRE components to log
* messages. This enables the runtime components to eliminate the
* static dependency of the logging facility and also defers the
* java.util.logging initialization until it is enabled.
* In addition, the PlatformLogger API can be used if the logging
* module does not exist.
*
* If the logging facility is not enabled, the platform loggers
* will output log messages per the default logging configuration
* (see below). In this implementation, it does not log the
* the stack frame information issuing the log message.
*
* When the logging facility is enabled (at startup or runtime),
* the java.util.logging.Logger will be created for each platform
* logger and all log messages will be forwarded to the Logger
* to handle.
*
* Logging facility is "enabled" when one of the following
* conditions is met:
* 1) a system property "java.util.logging.config.class" or
* "java.util.logging.config.file" is set
* 2) java.util.logging.LogManager or java.util.logging.Logger
* is referenced that will trigger the logging initialization.
*
* Default logging configuration:
* global logging level = INFO
* handlers = java.util.logging.ConsoleHandler
* java.util.logging.ConsoleHandler.level = INFO
* java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
*
* Limitation:
* <JAVA_HOME>/lib/logging.properties is the system-wide logging
* configuration defined in the specification and read in the
* default case to configure any java.util.logging.Logger instances.
* Platform loggers will not detect if <JAVA_HOME>/lib/logging.properties
* is modified. In other words, unless the java.util.logging API
* is used at runtime or the logging system properties is set,
* the platform loggers will use the default setting described above.
* The platform loggers are designed for JDK developers use and
* this limitation can be workaround with setting
* -Djava.util.logging.config.file system property.
*
* @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.
*/
/**
* PlatformLogger logging levels.
*/
public static enum Level {
// The name and value must match that of {@code java.util.logging.Level}s.
// Declare in ascending order of the given value for binary search.
ALL,
FINE,
INFO,
OFF;
/**
* Associated java.util.logging.Level lazily initialized in
* JavaLoggerProxy's static initializer only once
* when java.util.logging is available and enabled.
* Only accessed by JavaLoggerProxy.
*/
// ascending order for binary search matching the list of enum constants
private static final int[] levelValues = new int[] {
};
public int intValue() {
return levelValues[this.ordinal()];
}
switch (level) {
// ordering per the highest occurences in the jdk source
// finest, fine, finer, info first
}
// return the nearest Level value >= the given level,
// for level > SEVERE, return SEVERE and exclude OFF
}
}
private static boolean loggingEnabled;
static {
new PrivilegedAction<Boolean>() {
}
});
// force loading of all JavaLoggerProxy (sub)classes to make JIT de-optimizations
// less probable. Don't initialize JavaLoggerProxy class since
// java.util.logging may not be enabled.
try {
false,
PlatformLogger.class.getClassLoader());
false, // do not invoke class initializer
PlatformLogger.class.getClassLoader());
} catch (ClassNotFoundException ex) {
}
}
// Table of known loggers. Maps names to PlatformLoggers.
new HashMap<>();
/**
* Returns a PlatformLogger of a given name.
*/
}
}
return log;
}
/**
* Initialize java.util.logging.Logger objects for all platform loggers.
* This method is called from LogManager.readPrimordialConfiguration().
*/
public static synchronized void redirectPlatformLoggers() {
loggingEnabled = true;
}
}
}
/**
* Creates a new JavaLoggerProxy and redirects the platform logger to it
*/
private void redirectToJavaLoggerProxy() {
// the order of assignments is important
this.loggerProxy = jlp;
}
// DefaultLoggerProxy may be replaced with a JavaLoggerProxy object
// when the java.util.logging facility is enabled
// javaLoggerProxy is only set when the java.util.logging facility is enabled
if (loggingEnabled) {
} else {
}
}
/**
* A convenience method to test if the logger is turned off.
* (i.e. its level is OFF).
*/
public boolean isEnabled() {
return loggerProxy.isEnabled();
}
/**
* Gets the name for this platform logger.
*/
return loggerProxy.name;
}
/**
* Returns true if a message of the given level would actually
* be logged by this logger.
*
* @deprecated Use isLoggable(Level) instead.
*/
}
/**
* 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
*/
public int getLevel() {
}
/**
* Sets the log level.
*
* @deprecated Use setLevel(Level) instead
*/
}
/**
* Returns true if a message of the given level would actually
* be logged by this logger.
*/
throw new NullPointerException();
}
// performance-sensitive method: use two monomorphic call-sites
}
/**
* Get the log level that has been specified for this PlatformLogger.
* The result may be null, which means that this logger's
* effective level will be inherited from its parent.
*
* @return this PlatformLogger's level
*/
return loggerProxy.getLevel();
}
/**
* Set the log level specifying which message levels will be
* logged by this logger. Message levels lower than this
* value will be discarded. The level value {@link #OFF}
* can be used to turn off logging.
* <p>
* If the new level is null, it means that this node should
* inherit its level from its nearest ancestor with a specific
* (non-null) level value.
*
* @param newLevel the new value for the log level (may be null)
*/
}
/**
* Logs a SEVERE message.
*/
}
}
}
/**
* Logs a WARNING message.
*/
}
}
}
/**
* Logs an INFO message.
*/
}
}
}
/**
* Logs a CONFIG message.
*/
}
}
}
/**
* Logs a FINE message.
*/
}
}
}
/**
* Logs a FINER message.
*/
}
}
}
/**
* Logs a FINEST message.
*/
}
}
}
/**
* Abstract base class for logging support, defining the API and common field.
*/
private static abstract class LoggerProxy {
}
abstract boolean isEnabled();
}
/**
* Default platform logging support - output messages to System.err -
* equivalent to ConsoleHandler with SimpleFormatter.
*/
}
super(name);
}
boolean isEnabled() {
}
return level;
}
}
}
if (isLoggable(level)) {
}
}
if (isLoggable(level)) {
}
}
if (isLoggable(level)) {
}
}
}
// derive effective level (could do inheritance search like j.u.l.Logger)
}
// Copied from java.util.logging.Formatter.formatMessage
// Do the formatting.
try {
// No parameters. Just return format string.
return format;
}
// Is it a java.text style format?
// Ideally we could match with
// Pattern.compile("\\{\\d").matcher(format).find())
// However the cost is 14% higher, so we cheaply check for
// 1 of the first 4 parameters
}
return format;
// Formatting failed: use format string.
return format;
}
}
// minimize memory allocation
}
date,
name,
msg,
}
// Returns the caller's class and method's name; best effort
// if cannot infer, return the logger's name.
boolean lookingForLogger = true;
// Calling getStackTraceElement directly prevents the VM
// from paying the cost of building the entire stack frame.
if (lookingForLogger) {
// Skip all frames until we have found the first logger frame.
lookingForLogger = false;
}
} else {
// We've found the relevant frame.
break;
}
}
}
if (sourceClassName != null) {
} else {
return name;
}
}
}
/**
* JavaLoggerProxy forwards all the calls to its corresponding
* java.util.logging.Logger object.
*/
// initialize javaLevel fields for mapping from Level enum -> j.u.l.Level object
static {
}
}
}
super(name);
// level has been updated and so set the Logger's level
}
}
}
}
if (!isLoggable(level)) {
return;
}
// only pass String objects to the j.u.l.Logger which may
// be created by untrusted code
for (int i = 0; i < len; i++) {
}
}
boolean isEnabled() {
}
/**
* Returns the PlatformLogger.Level mapped from j.u.l.Level
* set in the logger. If the j.u.l.Logger is set to a custom Level,
* this method will return the nearest Level.
*/
try {
} catch (IllegalArgumentException e) {
}
}
}
}
}
}