0

After running the code below, I cannot find the word "Action One" in the log under log.nsf, does anyone know what is the problem?

import lotus.domino.*;

public class JavaAgent extends AgentBase {

  public void NotesMain() {
    try {
      Session session = getSession();
      AgentContext agentContext = 
      session.getAgentContext();
      // (Your code goes here) 
      Log log = session.createLog("Agent Log");
      log.openAgentLog();
      log.logAction("Action one");
      log.close();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }
}
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
Charles Yeung
  • 38,347
  • 30
  • 90
  • 130

2 Answers2

2

Agent log is visible in agent only:

This method stores output in the log for the current agent and fails if the program is not running as an agent. To display an agent log, select the agent and choose Agent - Log.

In case you want to see log entries in log.nsf use System.out.println(...) instead. The agent has to run on server to see the entries in server's log.nsf.

Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Yes, your are correct, I overlook... but do you know how can I write the log to `log.nsf`? – Charles Yeung Jun 19 '19 at 09:36
  • I updated my answer - use `System.out.println(...)` and run agent scheduled on server or call it with runOnServer. – Knut Herrmann Jun 19 '19 at 09:45
  • 1
    Be aware that the AgentLog has a size limit: only 64K text. Better use an ordinary NotesLog to a database (based on the AgentLog template). – D.Bugger Jun 19 '19 at 15:34
0

I suggest to use the OpenNTF project OpenLog to do your logging. It's an older project, but still supported. Your log entries will be written in a separate log database, so your system log won't be polluted. Furthermore, the log entries contain more information (like agent name, username and stacktrace) to make it easier to debug your application.

Tom Van Aken
  • 435
  • 2
  • 16