RFR: JDK-8005263: Logging APIs takes Supplier<String> for message

Remi Forax forax at univ-mlv.fr
Fri Dec 21 04:28:49 PST 2012


On 12/21/2012 10:22 AM, Alan Bateman wrote:
> On 21/12/2012 06:28, 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
> Henry - just a quick comment on the class description. I think it would
> be better not to include the sentence "Since 1.8 ..." as it that will
> quickly become a historical note. It would be much better (in my view)
> to just highlight the methods with something like "Several of the
> methods take a Supplier function ..." and make the potential performance
> benefit of using these methods clear.
>
> -Alan.
>

You should also add a note saying that the supplier can be specified as 
a lambda and in that case, the lambda *must* not capture value of local 
variable, otherwise a supplier object will be created each time you log 
something.

Rémi




More information about the lambda-dev mailing list