Name
Formatter
Synopsis
A Formatter
object is
used by a Handler
to convert a
LogRecord
to a String prior to logging it. Most
applications can simply use one one of the pre-defined concrete
subclasses: SimpleFormatter
or
XMLFormatter
. Applications requiring custom
formatting of log messages will need to subclass this class and
define the format( )
method to perform the desired
conversion. Such subclasses may find the formatMessage(
)
method useful: it performs localization using
java.util.ResourceBundle
and formatting using the
facilities of the java.text
package.
getHead( )
and getTail( )
return a prefix and suffix (such as opening and closing XML tags) for
a log file.
public abstract class Formatter { // Protected Constructors protected Formatter( ); // Public Instance Methods public abstract String format(LogRecord record); public String formatMessage(LogRecord record); synchronized public String getHead(Handler h); public String getTail(Handler h); }
Subclasses
SimpleFormatter
, XMLFormatter
Passed To
Handler.setFormatter( )
,
StreamHandler.StreamHandler( )
Returned By
Handler.getFormatter( )
Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.