The following code installs a LogListener object for all warning messages and then writes the information to a file.
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();
}
}
}
The following code registers a WarningLogListener object to receive warning messages. Call this code from anywhere that has access to the ServerContext such as a class constructor or synchronization script.