Logging patterns
There are but a few importantlogging patterns you can utilize to try to minimize the logging overhead implied, without any benefit from a functional point of view. Let's go through the most common ones.
Testing your level
The most important thing about a log message is its level. It is the information allowing you to efficiently ignore the messages - and their formatting/templating - if they will be ignored later anyway.
For instance, take this method that relies on loggers at different levels:
public void save(long id, Quote quote) { logger.finest("Value: " + quote); String hexValue = converter.toHexString(id); doSave(id, quote); logger.info("Saved: " + hexValue); logger.finest("Id: " + hexValue + ", quote=" + quote); }
This method is mixing debug and info log messages. Nevertheless, it is very likely that the debug messages will not be activated in production, but info messages will be if you use the info level as optional messages, then do the same reasoning...