1.在代理的Archive里引入log4j-1.2.16.jar
2.将log4j.properties拷贝到Lotus/domino目录下(nserver.exe所在目录)
### set log levels ###
log4j.rootLogger = debug , stdout , D , E
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %-4r [%t] %-5p %c %x - %m%n
### 输出到日志文件 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = logs/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
### 保存异常信息到单独文件 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = logs/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n
3.修改lotus/domino/jvm/lib/security/java.policy
在grant { }里添加permission java.lang.RuntimePermission "getClassLoader";
解决java.security.AccessControlException的问题。
4.样例代码
import lotus.domino.*;
// Import log4j classes.
import org.apache.log4j.Logger;
//import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.PropertyConfigurator;
public class JavaAgent extends AgentBase {
static Logger logger = Logger.getLogger(JavaAgent.class);
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
// (Your code goes here)
//BasicConfigurator.configure();
PropertyConfigurator.configure("log4j.properties");
logger.info("Entering application.");
logger.debug("Debug.");
System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径
logger.error("this is error.");
} catch(Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}
}