The following code installs a LogListener object for all information messages and then writes the information to a file.
class InfoLogListener implements LogListener {
FileOutputStream _outFile;
public InfoLogListener(FileOutputStream outFile) {
_outFile = outFile;
}
public void messageLogged(ServerContext sc, LogMessage msg) {
String user;
try {
if (msg.getType() != LogMessage.INFO) {
// this class deals exclusively with info
return;
}
user = msg.getUser();
if (user == null) {
user = "NULL";
}
_outFile.write(("Caught info"
+ " user=" + user
+ " text=" + msg.getText()
+ "\n").getBytes()
);
_outFile.flush();
}
catch(Exception e) {
// Print some info output to the MobiLink log.
e.printStackTrace();
}
}
}
The following code registers an InfoLogListener object to receive info messages. Call this code from anywhere that has access to the ServerContext such as a class constructor or synchronization script.