We are using java.util.logging
void log(Level level, Throwable thrown, Supplier msgSupplier)
and a few more convenience methods
But no varargs method. How come? Does this seem like a future enhancement...
There are multiple requests for Use varargs in java.util.logging.Logger on the OpenJDK site over the years. The API wasn't really maintained after JDK 5. Logging was updated in JDK 8 for Lambda Expressions but the logging guide wasn't updated for best practices just a few examples in the java.util.logging.Logger.
I created helper
public static void log(Logger logger, Level level, Throwable t, String msg, Object... params)
You might want to use the version in How can I log with params with a thrown? as it will retain the correct class and method name because the caller is still responsible for publishing the log record.
is there any good reason not to have something like
log(Level level, Throwable t, String msg, Object... params)
It is probably safe addition. Oracle ran a survey and it is clear they would prefer you to use a lambda or method reference with one of the log methods that takes a Supplier<String>
and lean on the java.util.Formatter providing the supporting for var-args.
} catch (IllegalArgumentException iae) {
logger.log(Level.SEVERE, iae, () -> String.format("%1$s is too many.", count));
}
Sugary sweet lambda syntax over vegetables!