The in the Handler‘s Java Logging API use a to java.util.logging.Formatter format the LogRecord ' s before writing it to an external system.
Java comes with built-in Formatter ' s (subclasses of Formatter ):
- Simpleformatter
- Xmlformatter
The various Handler ' s in the Java Logging API is use either of these Formatter , and the default, but can also set your own cust Om Formatter subclass on a Handler .
You can create your own by Formatter subclassing the java.util.logging.Formatter class. Here are a simple example:
public class MyFormatter extends Formatter { @Override public String format (LogRecord record) { return Record.getlevel () + ":" + Record.getmessage ();} }
The subclass must override the abstract format() method in the Formatter class. The String returned by the are forwarded to the format() External system by the Handler . Exactly how the string should are formatted are up to you.
The Formatter class also contains the convenience method formatMessage() which can be used to format the message using the ResourceBundle LogRecord. Here are an example:
public class MyFormatter extends Formatter { @Override public String format (LogRecord record) { return FormatMessage (record);} }
You won't often need to implement your own Formatter , but once in a while, if a specific log format is required, a custom c1/> may useful.
Java logging:formatters