Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.
指示日志消息属于警告。
final int LogMessage.WARNING
下面的代码为所有警告消息安装 [LogListener] 对象,然后将信息写到一个文件中。
class WarningLogListener implements LogListener { FileOutputStream _outFile; public WarningLogListener(FileOutputStream outFile) { _outFile = outFile; } public void messageLogged(ServerContext sc, LogMessage msg) { String user; try { if (msg.getType() != LogMessage.WARNING) { // This class deals exclusively with warnings. return; } user = msg.getUser(); if (user == null) { user = "NULL"; } _outFile.write(("Caught warning" + " user=" + user + " text=" + msg.getText() + "\n").getBytes() ); _outFile.flush(); } catch(Exception e) { // Print some warning output to the MobiLink log. e.printStackTrace(); } } }
以下代码注册 [WarningLogListener] 对象来接收警告消息。可以从有权访问 [ServerContext] 的任何位置(例如类构造函数或同步脚本)调用此代码。
ServerContext serv_context; FileOutputStream outFile serv_context.addWarningListener(new WarningLogListener(outFile));