public ianywhere.ml.script.LogMessageHolds the data associated with a log message.
Extends java.lang.Object.
All members of ianywhere.ml.script.LogMessage, including all inherited members.
The following example installs a LogListener for all warning, error, and info messages, then writes the information to a file. The following code installs a LogListener for all warning messages.
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 error output to the MobiLink log.
e.printStackTrace();
}
}
} |
The following code installs a LogListener for all error messages.
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();
}
}
} |
The following code installs a LogListener for all info messages.
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.ERROR) {
// 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 error output to the MobiLink log.
e.printStackTrace();
}
}
} |
The following code registers WarningLogListener, ErrorLogListener, and InfoLogListener to receive warning, error, and info messages respectively. Call this code from anywhere that has access to the ServerContext such as a class constructor or synchronization script.
// ServerContext serv_context; // FileOutputStream outFile serv_context.addWarningListener(new WarningLogListener(outFile)); serv_context.addErrorListener(new ErrorLogListener(outFile)); serv_context.addInfoListener(new InfoLogListener(outFile)); |
ERROR variable
INFO variable
WARNING variable
getType method
getUser method
getText method
| Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |