Examples: Log class

  1. This agent opens a mail log and sends it to the current user when the log closes.
    import lotus.domino.*;
    import java.util.Vector;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
          session.getAgentContext();
          // (Your code goes here) 
          Log log = session.createLog("Checkup Agent");
          Vector v = new Vector();
          v.addElement(session.getUserName());
          log.openMailLog(v, "Log for checkup agent");
          log.close();
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent opens a mail log, logs an action for each document in the current database, and sends the log to the current user when the log closes.
    import lotus.domino.*;
    import java.util.Vector;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
          session.getAgentContext();
          // (Your code goes here) 
          Log log = session.createLog("Cleansing Agent");
          Vector v = new Vector();
          v.addElement(session.getUserName());
          log.openMailLog(v, "Log for cleansing agent");
          Database db = agentContext.getCurrentDatabase();
          DocumentCollection dc = db.getAllDocuments();
          for (int j=0; j<dc.getCount(); j++) {
            log.logAction("Processed document " + (j+1)); }
          log.close();
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  3. This example opens a Domino® log and logs an error. The database agentlog.nsf must be based on the StdR4AgentLog template.
    import lotus.domino.*;
    public class JavaAgent extends AgentBase {
      public void NotesMain() {
        try {
          Session session = getSession();
          AgentContext agentContext = 
          session.getAgentContext();
          // (Your code goes here) 
          Agent agent = agentContext.getCurrentAgent();
          Database  db = agentContext.getCurrentDatabase();
          Log log = session.createLog(
          db.getTitle() + " on " + db.getServer());
          log.openNotesLog(null, "agentlog.nsf");
          View view = db.getView("foo");
          if (view==null) {
            log.logError(0, "Unable to find view foo"); }
          log.close();
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }