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