What if your log level is set so high that the log statement doesn't need to be performed? For instance, the statement is a debug statement, but the application is configured to only log warning messages or higher.
If it is expensive to create the log message, then it is a waste to create it if it isn't even going to be logged. Instead, you give it a supplier that tells the logger how to create the message, and it only gets called when the message is actually logged.
In general, you want to use the overload that takes a
String only if you are logging a literal message, or if you can create the message by concatenating very simple fields or local variables. When in doubt, use the
Supplier version.