Using templates in your messages

In the previous section, we looked at how to bypass the logging of a message. With JUL, it is often done with the methods called log levels, but there is a more generic log method called log, which can take the level, the message (or a key in a resource bundle if you internationalize the messages), and an object array parameter. This type of method exists in all frameworks and most of them will also provide some particular signatures with one, two, or more parameters to make it smoother to use.

In any case, the idea is to use the message as a pattern and the parameters to valorize some variables of the message. This is the feature this log pattern uses:

logger.log(Level.INFO, "id={0}, quote={1}", new Object[]{ ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.