All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.guicedee.logger.logging.HtmlFormatter Maven / Gradle / Ivy

Go to download

Provides Asynchronous and Dynamic Log Handler support for JDK1.8 logging API. Access via LogFactory.

There is a newer version: 62
Show newest version
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" + "\t\n" + "\t\n" + "\t\n" + "\n"; } // this method is called just after the handler using this // formatter is closed public String getTail(Handler h) { return "
LoglevelTimeLog Message
\n\n"; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy