With java.util.logging.Logger
, how can I log with params and a thrown?
final Object[] params;
final Throwable thrown;
I can't find any method with log(Level, String, Object[], Throwable)
.
Should I use log(Level, String.format(...), Throwable)
or log(Level, Throwable, () -> String.format(...))
?
There is no way to put both
String
andObject[]
to java.util.logging.Logger.I would convert
String[]
toString
and use:Also you can create your own
log
method that points tojava.util.logging.Logger.log
, something like:In general it looks like JUL is moving towards
log(Level, Throwable, () -> String.format(msg, params))
. However, this doesn't use the log record parameters array which has some utility with filters.Another option is to create a helper method to construct the log record and let the caller log it:
This is ideal because the caller logs the record which means that the inferred source method and source class names will be correct.