統合されたロギングに参加するよりはむしろ、 ログ・レコードをユーザー独自のログ・ハンドラーに伝搬したい場合があります。
スタンドアロン・ログ・ハンドラーを使用するには、 アプリケーションで useParentHandlers フラグを false に設定します。
カスタム・ハンドラーを作成するメカニズムは、IBM Developer Kit, Java Technology Edition に用意されている Handler クラスのサポートです。 Developer Kit によって実装されるハンドラーについて知識がない場合は、各種のテキストから、あるいは java.util.logging API の API 文書を読むことで、詳細な情報を得ることができます。
import java.io.FileOutputStream; import java.io.PrintWriter; import java.util.logging.Handler; import java.util.logging.LogRecord; /** * MyCustomHandler outputs contents to a specified file */ public class MyCustomHandler extends Handler { FileOutputStream fileOutputStream; PrintWriter printWriter; public MyCustomHandler(String filename) { super(); // check input parameter if (filename == null) filename = "mylogfile.txt"; try { // initialize the file fileOutputStream = new FileOutputStream(filename); printWriter = new PrintWriter(fileOutputStream); } catch (Exception e) { // implement exception handling... } } /* (non-API documentation) * @see java.util.logging.Handler#publish(java.util.logging.LogRecord) */ public void publish(LogRecord record) { // ensure that this log record should be logged by this Handler if (!isLoggable(record)) return; // Output the formatted data to the file printWriter.println(getFormatter().format(record)); } /* (non-API documentation) * @see java.util.logging.Handler#flush() */ public void flush() { printWriter.flush(); } /* (non-API documentation) * @see java.util.logging.Handler#close() */ public void close() throws SecurityException { printWriter.close(); } }