com.guicedee.logger.logging.HtmlFormatter 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.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
public class HtmlFormatter extends Formatter {
// this method is called for every log records
public String format(LogRecord rec) {
StringBuffer buf = new StringBuffer(1000);
buf.append("\n");
// colorize any levels >= WARNING in red
if (rec.getLevel()
.intValue() >= Level.WARNING.intValue()) {
buf.append("\t");
buf.append("");
buf.append(rec.getLevel());
buf.append("");
}
else {
buf.append("\t ");
buf.append(rec.getLevel());
}
buf.append(" \n");
buf.append("\t");
buf.append(calcDate(rec.getMillis()));
buf.append(" \n");
buf.append("\t");
buf.append(formatMessage(rec));
buf.append(" \n");
buf.append(" \n");
return buf.toString();
}
private String calcDate(long millisecs) {
SimpleDateFormat date_format = new SimpleDateFormat("MMM dd,yyyy HH:mm");
Date resultdate = new Date(millisecs);
return date_format.format(resultdate);
}
// this method is called just after the handler using this
// formatter is created
public String getHead(Handler h) {
return "\n\n\n"
+ "\n"
+ "\n"
+ "" + (new Date()) + "
\n"
+ "\n"
+ "\n"
+ "\tLoglevel \n"
+ "\tTime \n"
+ "\tLog Message \n"
+ " \n";
}
// this method is called just after the handler using this
// formatter is closed
public String getTail(Handler h) {
return "
\n\n