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