This is harder than it should be, but it's possible. The logging framework ends up passing log records to handlers, which use a formatter to format them, producing strings. By default, they use a SimpleFormatter, whose formatMessage method ends up using MessageFormat to do the work.
It's possible to modify a MessageFormat to not format numbers, and just convert them using toString. So we need to write our own formatter which uses MessageFormat, but does that. It's ugly but it works.
Here's what i wrote:
public class SimplerFormatter extends SimpleFormatter {
private static final Format TRIVIAL_FORMAT = new Format() {
@Override
public StringBuffer format(Object obj, StringBuffer buf, FieldPosition pos) {
pos.setBeginIndex(buf.length());
buf.append(obj);
pos.setEndIndex(buf.length());
return buf;
}
@Override
public Object parseObject(String source, ParsePosition pos) {
throw new UnsupportedOperationException();
}
};
@Override
public String formatMessage(LogRecord record) {
String format = record.getMessage();
Object[] parameters = record.getParameters();
if (parameters == null || parameters.length == 0) {
return format;
}
try {
return newMessageFormat(format).format(parameters);
} catch (Exception e) {
return format;
}
}
private static MessageFormat newMessageFormat(String format) {
MessageFormat messageFormat = new MessageFormat(format);
Format[] argumentFormats = messageFormat.getFormats();
for (int i = 0; i < argumentFormats.length; i++) {
if (argumentFormats[i] == null) {
messageFormat.setFormat(i, TRIVIAL_FORMAT);
}
}
return messageFormat;
}
}
Pass an instance of that to Handler::setFormat, and that handler will no longer format your numbers.