net.lakis.cerebro.log.LogFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cerebro Show documentation
Show all versions of cerebro Show documentation
A framework to handle dependency injection and allowing users to communicate with the application
using command line.
The newest version!
package net.lakis.cerebro.log;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
public class LogFormatter extends Formatter {
@Override
public String format(LogRecord record) {
String message = formatMessage(record);
if (record.getThrown() == null) {
return String.format("[%s] %s", record.getLevel().toString(), message);
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println();
record.getThrown().printStackTrace(pw);
pw.close();
return String.format("[%s] %s%n%s%n", record.getLevel().toString(), message, sw.toString());
}
}