com.guicedee.logger.logging.LogFormatter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guiced-log-master Show documentation
Show all versions of guiced-log-master Show documentation
Provides Asynchronous and Dynamic Log Handler support for JDK1.8 logging API. Access via LogFactory.
package com.guicedee.logger.logging;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.LogRecord;
abstract class LogFormatter
extends java.util.logging.Formatter
{
StringBuilder printException(LogRecord record)
{
StringBuilder output = new StringBuilder();
if (record.getThrown() != null)
{
Throwable t = record.getThrown();
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw))
{
t.printStackTrace(pw);
}
output.append(LogColourFormatter.getAnsiReset());
output.append(sw.toString());
}
return output;
}
String processParameters(String output, LogRecord record)
{
if (record.getParameters() != null && record.getParameters().length > 0)
{
for (int n = 0; n < record.getParameters().length; n++)
{
Object o = record.getParameters()[n];
if (o == null)
{
continue;
}
String replace = "\\{" + n + "}";
String replacable = o.toString();
output = output.replaceAll(replace, replacable);
}
}
return output;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy