public boolean writeToLog() {
boolean retval = false;
try {
Database db;
Document logDoc;
RichTextItem rtitem;
Database docDb;
if (!StringUtil.equals(super.getCurrentDatabasePath(), Factory.getSession().getCurrentDatabase().getFilePath())) {
reinitialiseSettings();
}
if (StringUtil.isEmpty(getLogEmail())) {
db = getLogDb();
} else {
db = XSPUtil.getCurrentSessionAsSigner().getDatabase(getThisServer(), "mail.box", false);
}
if (db == null) {
System.out.println("Could not retrieve database at path " + getLogDbName());
return false;
}
logDoc = db.createDocument();
rtitem = logDoc.createRichTextItem("LogDocInfo");
logDoc.appendItemValue("Form", super.getLogFormName());
Throwable ee = getBase();
String errMsg = "";
if (null != ee) {
StackTraceElement ste = ee.getStackTrace()[0];
if (ee instanceof NotesException) {
logDoc.replaceItemValue("LogErrorNumber", ((NotesException) ee).id);
errMsg = ((NotesException) ee).text;
} else if ("Interpret exception".equals(ee.getMessage()) && ee instanceof com.ibm.jscript.JavaScriptException) {
com.ibm.jscript.InterpretException ie = (com.ibm.jscript.InterpretException) ee;
errMsg = "Expression Language Interpret Exception " + ie.getExpressionText();
} else {
errMsg = ee.getMessage();
}
if (LogType.TYPE_EVENT.getValue().equals(getEventType())) {
if (!getSuppressEventStack()) {
logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
}
} else {
logDoc.replaceItemValue("LogStackTrace", getStackTrace(ee));
}
logDoc.replaceItemValue("LogErrorLine", ste.getLineNumber());
logDoc.replaceItemValue("LogFromMethod", ste.getClass() + "." + ste.getMethodName());
}
if ("".equals(errMsg)) {
errMsg = getMessage();
}
logDoc.replaceItemValue("LogErrorMessage", errMsg);
logDoc.replaceItemValue("LogEventTime", getEventTime());
logDoc.replaceItemValue("LogEventType", getEventType());
// If greater than 32k, put in logDocInfo
if (getMessage().length() > 32000) {
rtitem.appendText(getMessage());
rtitem.addNewLine();
} else {
logDoc.replaceItemValue("LogMessage", getMessage());
}
logDoc.replaceItemValue("LogSeverity", getSeverity().getName());
logDoc.replaceItemValue("LogFromDatabase", getCurrentDatabase().getFilePath());
logDoc.replaceItemValue("LogFromServer", getThisServer());
logDoc.replaceItemValue("LogFromAgent", getThisAgent());
logDoc.replaceItemValue("LogAgentLanguage", "Java");
logDoc.replaceItemValue("LogUserName", Factory.getSession().getUserName());
logDoc.replaceItemValue("LogEffectiveName", Factory.getSession().getEffectiveUserName());
logDoc.replaceItemValue("LogAccessLevel", getAccessLevel());
logDoc.replaceItemValue("LogUserRoles", getUserRoles());
logDoc.replaceItemValue("LogClientVersion", getClientVersion());
logDoc.replaceItemValue("LogAgentStartTime", getStartTime());
if (getErrDoc() != null) {
docDb = getErrDoc().getParentDatabase();
rtitem.appendText("The document associated with this event is:");
rtitem.addNewLine(1);
rtitem.appendText("Server: " + docDb.getServer());
rtitem.addNewLine(1);
rtitem.appendText("Database: " + docDb.getFilePath());
rtitem.addNewLine(1);
rtitem.appendText("UNID: " + getErrDoc().getUniversalID());
rtitem.addNewLine(1);
rtitem.appendText("Note ID: " + getErrDoc().getNoteID());
rtitem.addNewLine(1);
rtitem.appendText("DocLink: ");
rtitem.appendDocLink(super.getErrDoc(), getErrDoc().getUniversalID());
}
// make sure Depositor-level users can add documents too
logDoc.appendItemValue("$PublicAccess", "1");