Hi Henry,
Have you considered reversing the positions of Supplier and Throwable
arguments in methods that take both? For example instead of:
695 public void logEx(Level level, Supplier<String> msgSupplier, Throwable
thrown) {
the following:
695 public void logEx(Level level,Throwable thrown, Supplier<String>
msgSupplier) {
If one chooses this form (taking Throwable and Supplier) it might be
because there is some code in the lambda expression that is turned into
Suppier that spans multiple lines. Better compact multi-line formatting
is possible if lambda is last argument:
logger.logEx(
Level.WARN,
() -> {
StringBuilder sb = new StringBuilder();
for (Foo foo : foos) {
sb.append(sb.length() == 0 ? "[" : ",");
sb.append(foo);
}
if (sb.length() > 0) sb.append("]");
return sb.toString();
},
exception
);
vs.
logger.logEx(Level.WARN, exception, () -> {
StringBuilder sb = new StringBuilder();
for (Foo foo : foos) {
sb.append(sb.length() == 0 ? "[" : ",");
sb.append(foo);
}
if (sb.length() > 0) sb.append("]");
return sb.toString();
});
It might be (haven't checked) that you don't need another name for a
method (logEx) in that case too.
Regards, Peter
On 12/21/2012 07:28 AM, Henry Jen wrote:
Hi,
This patch adds a couple APIs to java.util.logging.Logger so that
construction of log messages only occurs when it is actually to be
logged by using Supplier<String> instead of String.
Since the idea is to avoid unnecessary construction of log messages,
thus APIs imply formatting are not provided. Thus all forms of logrb and
log with Parameters are not included.
log with Throwable are named to be logEx or logpEx to avoid null
ambiguous as it seems like it's quite common usage with
logger.log(level, null, thrown)
Specdiff and webrev can be found at following,
http://cr.openjdk.java.net/~henryjen/ccc/8005263.0/specdiff/diff.html
http://cr.openjdk.java.net/~henryjen/ccc/8005263.0/webrev/
Cheers,
Henry