WebSphere Application Server Version 6.1 Feature Pack for Web Services   
             オペレーティング・システム: AIX , HP-UX, i5/OS, Linux, Solaris, Windows, Windows Vista, z/OS

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

例: java.util.logging を使用したカスタム・フォーマッターの作成

フォーマッターは、イベントをフォーマットします。 ハンドラーは、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();
	}
}



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

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

最終更新: Jan 21, 2008 4:10:06 PM EST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.wsfep.multiplatform.doc/info/ae/ae/rtrb_createformatter.html