package de.uhilger.transit; import java.text.DateFormat; import java.util.Locale; import java.util.Date; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.logging.XMLFormatter; /** * a log formatter which displays only message and date/time * * @author Ulrich Hilger * @author http://uhilger.de * @author published under the terms and conditions of the * GNU General Public License * * @version 2, April 20, 2012 (changed from version 1, July 11, 2004) */ public class TextLogFormatter extends XMLFormatter { /** constructor */ public TextLogFormatter() { lineSeparator = System.getProperty("line.separator"); } /** * format a log record * @param record LogRecord the record to format * @return String the formatted log record */ public String format(LogRecord record) { StringBuffer buf = new StringBuffer(); DateFormat df = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.MEDIUM, Locale.getDefault()); buf.append(df.format(new Date(record.getMillis()))); buf.append(" "); buf.append(record.getMessage()); buf.append(" "); buf.append(record.getLevel()); buf.append(" "); buf.append(record.getSourceClassName()); buf.append("."); buf.append(record.getSourceMethodName()); buf.append(lineSeparator); return buf.toString(); } /** * get the header string * @param h Handler the handler * @return String the header string */ public String getHead(Handler h) { return ""; } /** * get the trailing string * @param h Handler the handler * @return String the trailing string */ public String getTail(Handler h) { return ""; } /** holds the system dependent line separator */ private String lineSeparator; }