changeset 6417:dfed78f69c8b

Add log(Level, Factory<String>) to j.u.logging
author briangoetz
date Thu, 15 Nov 2012 18:15:00 -0500
parents 1257aeafc7f5
children c5b238ae25fe
files src/share/classes/java/util/logging/Logger.java
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/logging/Logger.java	Thu Nov 15 17:54:00 2012 -0500
+++ b/src/share/classes/java/util/logging/Logger.java	Thu Nov 15 18:15:00 2012 -0500
@@ -30,6 +30,7 @@
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.security.*;
 import java.lang.ref.WeakReference;
+import java.util.function.Factory;
 
 /**
  * A Logger object is used to log messages for a specific
@@ -567,6 +568,26 @@
     }
 
     /**
+     * Log a message, which is only to be constructed if the logging level
+     * is such that the message will actually be logged.
+     * <p>
+     * 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.
+     * <p>
+     * @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, Factory<String> msgSupplier) {
+        if (level.intValue() < levelValue || levelValue == offValue) {
+            return;
+        }
+        LogRecord lr = new LogRecord(level, msgSupplier.make());
+        doLog(lr);
+    }
+
+    /**
      * Log a message, with one object parameter.
      * <p>
      * If the logger is currently enabled for the given message