Mandy, I agree it should be well known; but I fixed several cases in awt/net code where isLoggable() calls were missing.
I think it is quite cheap to remind good practices in the PlatformLogger / jul Logger javadoc ... PS: maybe some quality control tools could check such missing tests (PMD can do it)... I believe this was mentioned somewhere in j.u.logging. A better solution > may be to take java.util.function.Supplier parameter that constructs the > log message lazily (see > http://download.java.net/jdk8/docs/api/java/util/logging/Logger.html#fine(java.util.function.Supplier). > I can file a RFE to investigate the use of Supplier as in j.u.l.Logger. > Very interesting feature, but I am still not aware of such JDK 8 features (lambda) ... it seems nice but maybe the syntax will be more complicated / verbose than our usual log statements: log.fine(""...) Laurent > > On 4/5/2013 1:55 AM, Laurent Bourgès wrote: > > Mandy, > > I would like to add few performance advices in the PlatformLogger Javadoc: > " > NOTE: For performance reasons, PlatformLogger usages should take care of > avoiding useless / wasted object creation and method calls related to * > disabled* log statements: > Always use isLoggable(level) wrapping logs at levels (FINEST, FINER, FINE, > CONFIG): > > Bad practices: > - string concat: > log.fine("message" + value); // means > StringBuilder(message).append(String.valueOf(value)).toString(): 2 objects > created and value.toString() called > - varags: > log.fine("message {0}", this); // create an Object[] > > Best practices: > if (log.isLoggable(PlatformLogger.FINE) { > log.fine("message" + value); > } > > if (log.isLoggable(PlatformLogger.FINE) { > log.fine("message {0}", this); > } > " > > What is your opinion ? > > Thanks for the given explanations and I hope that this patch will be > submitted soon to JDK8 repository. > > Laurent > >