Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
ログメッセージがエラーであることを示します。
final int LogMessage.ERROR
次のコードは、すべてのエラーメッセージ用に LogListener オブジェクトをインストールしてから、その情報をファイルに書き込みます。
class ErrorLogListener implements LogListener { FileOutputStream _outFile; public ErrorLogListener(FileOutputStream outFile) { _outFile = outFile; } public void messageLogged(ServerContext sc, LogMessage msg) { String user; try { if (msg.getType() != LogMessage.ERROR) { //this class deals exclusively with errors return; } user = msg.getUser(); if (user == null) { user = "NULL"; } _outFile.write(("Caught error" + " user=" + user + " text=" + msg.getText() + "\n").getBytes() ); _outFile.flush(); } catch(Exception e) { // Print some error output to the MobiLink log. e.printStackTrace(); } } }
次のコードは ErrorLogListener オブジェクトを登録して、エラーメッセージを受信します。クラスコンストラクタや同期スクリプトなど、ServerContext にアクセスできる任意の場所からこのコードを呼び出してください。
ServerContext serv_context; FileOutputStream outFile serv_context.addErrorListener(new ErrorLogListener(outFile));