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( )
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access