SysloglikeFormatter.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* ident "%Z%%M% %I% %E% SMI" */
/**
* Formats a LogRecord in a human-readable, <code>syslog</code>-like
* format, and is intended for use with non-syslog handlers, such as
* FileHandler.
*
* Multi-line messages are automatically indented by four spaces to make
* subsequent lines easier to differentiate from new records.
*/
public class SysloglikeFormatter extends Formatter {
/**
* The date set for each published Record.
*/
/**
* Format string for published dates.
*/
private final static String dateFormat =
"MMM d kk:mm:ss";
/**
* For published dates, the formatter.
*/
private DateFormat dateFormatter;
/**
* For published dates, the argument to date formatter.
*/
/**
* Line separator string.
*/
"line.separator"));
/**
* Flag to set whether log records should indicate the name of
* the class generating the record, if possible. (default
* false)
*/
private boolean useClassName = false;
/**
* Flag to set whether log records should indicate the record's
* logger, if useClassName isn't set and the class name was
* available. (default false)
*/
private boolean useLoggerName = false;
/**
* Flag to set whether log records should indicate the last
* component of the record's logger name, if useLoggerName isn't
* set. (default true)
*/
private boolean useShortLoggerName = true;
/**
* Flag to set whether log records should indicate the method
* used to invoke the logger, if available. (default false)
*/
private boolean useMethodName = false;
/**
* Flag to set whether each record should be split into two
* lines such that the severity and message are on a line by
* themselves. (default false)
*/
private boolean useTwoLineStyle = false;
/**
* Format the given LogRecord.
* @param record the log record to be formatted.
* @return a formatted log record.
*/
{
if (dateFormatter == null)
} else if (useLoggerName) {
}
} else if (useShortLoggerName) {
if (loggerName != null) {
if (lastDot >= 0)
lastDot + 1);
}
}
}
if (useTwoLineStyle)
else
"with tracing information: ").toString());
}
}
}