Is it possible to print the thread name in the log statements generated by java.util.logging.Logger?
One alternative is to do something like the following:
logger.info(thread.getName() + " some useful info");
but it’s repetitive and the logging framework should handle it.
Embarrassingly, but looks like
java.util.loggingcan’t do this…The default
java.util.logging.SimpleFormatterdoesn’t have the ability to log thread name at all. Thejava.util.logging.FileHandlersupports few template placeholders, none of them is thread name.java.util.logging.XMLFormatteris the closest one, but only logs thread id:If you think we’re getting close – we’re not.
LogRecordclass only holds the thread ID, not its name – not very useful.