tags:

views:

30

answers:

1

NetBeans recommended that I change the way that logging statements that have string concatenation are written, stating Convert string concatenation to a message template so that a statement such as:

log.severe("Completed at:  " + new Date());

got changed to

log.log(Level.SEVERE, "Completed at:  {0}", new Date());

The problem is that now the Date doesn't get printed. Instead, the string "{0}" literatlly gets printed instead. Is there something else I was suppose to do?

A: 

I know that PrintStream has a format method that works that way, though Java uses the C-like % prefix instead of the C#-like {} wrapper. But Logger has no such method. You are instead invoking an override of log which in my experience only logs the string exactly as given, and does nothing with the Object parameter.

jdmichal