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