--- old/src/share/classes/java/util/logging/Logger.java 2012-12-20 21:36:14.270786509 -0800 +++ new/src/share/classes/java/util/logging/Logger.java 2012-12-20 21:36:14.102786507 -0800 @@ -30,6 +30,8 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.security.*; import java.lang.ref.WeakReference; +import java.util.function.Block; +import java.util.function.Supplier; /** * A Logger object is used to log messages for a specific @@ -96,6 +98,12 @@ * for example a format string "{0} {1}" would format two parameters * as strings. *
+ * Since 1.8, a set of methods alternatively take a "msgSupplier" instead of
+ * a "msg" argument. This version takes a {@link Supplier}{@code
+ *
* When mapping ResourceBundle names to ResourceBundles, the Logger
* will first try to use the Thread's ContextClassLoader. If that
* is null it will try the SystemClassLoader instead. As a temporary
@@ -543,6 +551,22 @@
log(lr);
}
+ // private support method for logging.
+ // message and LogRecord are only constucted when it really need to
+ // be logged
+ private void doLog(Level level, Supplier
+ * If the logger is currently enabled for the given message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param level One of the message level identifiers, e.g., SEVERE
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ */
+ public void log(Level level, Supplier
* If the logger is currently enabled for the given message
@@ -632,6 +673,29 @@
doLog(lr);
}
+ /**
+ * Log a in-time constructed message, with associated Throwable information.
+ *
+ * If the logger is currently enabled for the given message level then the
+ * message is constructed by invoking the provided supplier function. The
+ * message and the given {@link Throwable} are then stored in a {@link
+ * LogRecord} which is forwarded to all registered output handlers.
+ *
+ * Note that the thrown argument is stored in the LogRecord thrown
+ * property, rather than the LogRecord parameters property. Thus is it
+ * processed specially by output Formatters and is not treated
+ * as a formatting parameter to the LogRecord message property.
+ *
+ * @param level One of the message level identifiers, e.g., SEVERE
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @param thrown Throwable associated with log message.
+ * @since 1.8
+ */
+ public void logEx(Level level, Supplier
+ * If the logger is currently enabled for the given message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param level One of the message level identifiers, e.g., SEVERE
+ * @param sourceClass name of class that issued the logging request
+ * @param sourceMethod name of method that issued the logging request
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void logp(Level level, String sourceClass, String sourceMethod,
+ Supplier
@@ -732,7 +820,7 @@
* @param thrown Throwable associated with log message.
*/
public void logp(Level level, String sourceClass, String sourceMethod,
- String msg, Throwable thrown) {
+ String msg, Throwable thrown) {
if (level.intValue() < levelValue || levelValue == offValue) {
return;
}
@@ -743,6 +831,37 @@
doLog(lr);
}
+ /**
+ * Log a in-time constructed message, specifying source class and method,
+ * with associated Throwable information.
+ *
+ * If the logger is currently enabled for the given message level then the
+ * message is constructed by invoking the provided supplier function. The
+ * message and the given {@link Throwable} are then stored in a {@link
+ * LogRecord} which is forwarded to all registered output handlers.
+ *
+ * Note that the thrown argument is stored in the LogRecord thrown
+ * property, rather than the LogRecord parameters property. Thus is it
+ * processed specially by output Formatters and is not treated
+ * as a formatting parameter to the LogRecord message property.
+ *
+ * @param level One of the message level identifiers, e.g., SEVERE
+ * @param sourceClass name of class that issued the logging request
+ * @param sourceMethod name of method that issued the logging request
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @param thrown Throwable associated with log message.
+ * @since 1.8
+ */
+ public void logpEx(Level level, String sourceClass, String sourceMethod,
+ Supplier
+ * If the logger is currently enabled for the SEVERE message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void severe(Supplier
+ * If the logger is currently enabled for the WARNING message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void warning(Supplier
+ * If the logger is currently enabled for the INFO message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void info(Supplier
+ * If the logger is currently enabled for the CONFIG message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void config(Supplier
+ * If the logger is currently enabled for the FINE message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void fine(Supplier
+ * If the logger is currently enabled for the FINER message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void finer(Supplier
+ * If the logger is currently enabled for the FINEST message
+ * level then the message is constructed by invoking the provided
+ * supplier function and forwarded to all the registered output
+ * Handler objects.
+ *
+ * @param msgSupplier A function, which when called, produces the
+ * desired log message
+ * @since 1.8
+ */
+ public void finest(Supplier