フォーマッターは、イベントをフォーマットします。 ハンドラーは、1 つ以上のフォーマッターに関連付けられます。
カスタマー・フォーマッターを作成するメカニズムは、IBM Developer Kit, Java Technology Edition に用意されている Formatter クラスのサポートです。 Developer Kit によって実装されるフォーマッターについて知識がない場合は、各種のテキストから、あるいは java.util.logging API の API 文書を読むことで、詳細な情報を得ることができます。
import java.util.Date; import java.util.logging.Formatter; import java.util.logging.LogRecord; /** * MyCustomFormatter formats the LogRecord as follows: * date level localized message with parameters */ public class MyCustomFormatter extends Formatter { public MyCustomFormatter() { super(); } public String format(LogRecord record) { // Create a StringBuffer to contain the formatted record // start with the date. StringBuffer sb = new StringBuffer(); // Get the date from the LogRecord and add it to the buffer Date date = new Date(record.getMillis()); sb.append(date.toString()); sb.append(" "); // Get the level name and add it to the buffer sb.append(record.getLevel().getName()); sb.append(" "); // Get the formatted message (includes localization // and substitution of paramters) and add it to the buffer sb.append(formatMessage(record)); sb.append("¥ n"); return sb.toString(); } }