SimpleConsoleFormatter.java revision 1238
58N/A/*
58N/A * CDDL HEADER START
58N/A *
58N/A * The contents of this file are subject to the terms of the
58N/A * Common Development and Distribution License (the "License").
58N/A * You may not use this file except in compliance with the License.
58N/A *
58N/A * See LICENSE.txt included in this distribution for the specific
58N/A * language governing permissions and limitations under the License.
58N/A *
58N/A * When distributing Covered Code, include this CDDL HEADER in each
58N/A * file and include the License file at LICENSE.txt.
58N/A * If applicable, add the following below this CDDL HEADER, with the
58N/A * fields enclosed by brackets "[]" replaced with your own identifying
58N/A * information: Portions Copyright [yyyy] [name of copyright owner]
58N/A *
58N/A * CDDL HEADER END
58N/A */
830N/A
58N/A/*
58N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
58N/A */
850N/A
58N/Apackage org.opensolaris.opengrok;
830N/A
850N/Aimport java.util.Date;
830N/Aimport java.util.logging.Formatter;
58N/Aimport java.util.logging.Level;
128N/Aimport java.util.logging.LogRecord;
58N/A
128N/A/**
58N/A * Opengrok console formatter
850N/A * Creates a logentry on the console using the following format
58N/A * HH:MM:ss <loglevel>: <logmessage>
58N/A * @author Lubos Kosco
58N/A */
58N/Afinal public class SimpleConsoleFormatter extends Formatter {
77N/A
77N/A private final java.text.SimpleDateFormat formatter =
867N/A new java.text.SimpleDateFormat("HH:mm:ss");
77N/A private static final String lineSeparator = System.
867N/A getProperty("line.separator");
850N/A
850N/A private String ts(Date date) {
850N/A return formatter.format(date);
867N/A }
850N/A
850N/A @Override
850N/A public String format(LogRecord record) {
850N/A StringBuilder sb = new StringBuilder();
58N/A sb.append(ts(new Date(record.getMillis())));
874N/A sb.append(" ");
850N/A sb.append(record.getLevel().getName());
850N/A sb.append(": ");
850N/A sb.append(formatMessage(record));
850N/A Throwable thrown = record.getThrown();
850N/A if (null != thrown && record.getLevel().intValue() < Level.CONFIG.intValue()) {
850N/A sb.append(lineSeparator);
850N/A java.io.ByteArrayOutputStream ba=new java.io.ByteArrayOutputStream();
866N/A thrown.printStackTrace(new java.io.PrintStream(ba, true));
850N/A sb.append(ba.toString());
866N/A }
850N/A sb.append(lineSeparator);
850N/A return sb.toString();
830N/A }
850N/A}
867N/A