WebSphere Application Server for z/OS, Version 6.1   
             オペレーティング・システム: z/OS

             目次と検索結果のパーソナライズ化

例: java.util.logging を使用したカスタム・ログ・ハンドラーの作成

統合されたロギングに参加するよりはむしろ、 ログ・レコードをユーザー独自のログ・ハンドラーに伝搬したい場合があります。

スタンドアロン・ログ・ハンドラーを使用するには、 アプリケーションで 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();
	}
}



関連タスク
ロガー階層の構成
ログ・リソース・バンドルおよびメッセージ・ファイルの作成
ロガーの使用
関連資料
例: java.util.logging を使用したカスタム・フィルターの作成
例: java.util.logging を使用したカスタム・フォーマッターの作成
例: カスタムのハンドラー、フィルター、およびフォーマッターの追加
参照トピック    

ご利用条件 | フィードバック

最終更新: Jan 21, 2008 9:12:22 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.zseries.doc/info/zseries/ae/rtrb_createhandler.html