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;
1178N/Aimport java.util.logging.Level;
308N/Aimport java.util.logging.LogRecord;
308N/A
308N/A/**
308N/A * Opengrok logfile formatter
308N/A * Creates a logentry in the logfile on the following format
308N/A * [#|YYYY-MM-DD HH:MM:ss.SSSZ |<loglevel>|<version>|OG|T=<threadnumber>|
308N/A * <Class.method>: <logmessage> |#]
308N/A * @author Jan S Berg
308N/A */
308N/Afinal public class FileLogFormatter extends Formatter {
1190N/A
308N/A private final java.text.SimpleDateFormat formatter =
308N/A new java.text.SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss.SSSZ");
1238N/A private static final String lineSeparator = System.
308N/A getProperty("line.separator");
1190N/A
308N/A private String ts(Date date) {
308N/A return formatter.format(date);
308N/A }
1190N/A
308N/A private String classNameOnly(String name) {
308N/A int index = name.lastIndexOf('.') + 1;
308N/A return name.substring(index);
308N/A }
1190N/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(" |");
308N/A String loglevel = record.getLevel().getName();
308N/A sb.append(loglevel);
308N/A sb.append("|");
308N/A sb.append("V");
308N/A sb.append(Info.getVersion());
308N/A sb.append("|OG|");
1190N/A sb.append("T=");
308N/A sb.append(record.getThreadID());
1190N/A sb.append("| ");
308N/A sb.append(classNameOnly(record.getSourceClassName()));
308N/A sb.append('.');
1062N/A sb.append(formatMessage(record));
308N/A sb.append(": ");
308N/A sb.append(record.getMessage());
308N/A Throwable thrown = record.getThrown();
1178N/A if (null != thrown && record.getLevel().intValue() < Level.CONFIG.intValue()) {
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}