I wrote a custom Formatter as suggested by jmehrens. If I need something more complicated I may try moving to another framework like log4j but this does what I want for now. Thanks for the advice!
Formatter formatter = new Formatter() {
@Override
public String format(LogRecord record) {
String source = "";
if (record.getSourceClassName() != null) {
try {
source = Class.forName(record.getSourceClassName()).getSimpleName();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (record.getSourceMethodName() != null) {
source += " " + record.getSourceMethodName();
}
} else {
source = record.getLoggerName();
}
String message = formatMessage(record);
String throwable = "";
if (record.getThrown() != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println();
record.getThrown().printStackTrace(pw);
pw.close();
throwable = sw.toString();
}
return String.format(getLogFormat(), new Date(record.getMillis()), source,
record.getLoggerName(), record.getLevel(), message, throwable);
}
};
Loggerwith the full class name I suppose. Just put in the simple class name there.logp(Level level, String sourceClass, String sourceMethod, String msg)method to do your logging calls, passing in the simple class name and a perhaps empty method name, as this builds theLogRecords source entry But I'd rather recommend that you take your time to have a look at the different logging frameworks (skf4j, logback, log4j2 etc.), because they are way more flexible especially when it comes to formatting and controlling the output.