LogMessage class

Syntax
public ianywhere.ml.script.LogMessage
Remarks

Holds the data associated with a log message.

Extends java.lang.Object.

See also
Members

All members of ianywhere.ml.script.LogMessage, including all inherited members.

Example

The following example installs a LogListener for all warning messages and error messages, and writes the information to a file. One implementation of LogListener is created for warning messages and the other is created for error messages. 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 registers WarningLogListener and ErrorLogListener to receive warning and error 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 ));

ERROR variable
WARNING variable
getType method
getUser method
getText method