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?
Assuming that the code snippet you posted is not the original code that was causing problems... Having a single apostrophe in your message will cause the type of a problem you described. java.util.logging.Logger.log
passes the message to java.text.MessageFormat
which requires you to escape apostrophes.
For example:
log.log( Level.FINE, "Can't handle {0}.", id );
log.log( Level.FINE, "Can''t handle {0}.", id );
Logs:
Cant handle {0}.
Can't handle ID0001.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With