1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.goetz.domino.log4j;
18
19 import lotus.domino.Database;
20 import lotus.domino.NotesException;
21 import lotus.domino.Session;
22
23 import org.apache.log4j.helpers.LogLog;
24 import org.apache.log4j.spi.LoggingEvent;
25
26 /***
27 * This appender is the basis for servlet based appenders.
28 *
29 * @author Bernd G?tz
30 */
31 abstract public class DominoAppender extends AbstractAppender {
32
33
34
35
36 protected void initialize(LoggingEvent event)
37 throws NotesException {
38 doc.setApplicationPath(getApplicationPath());
39 String appName = doc.getApplicationName();
40 if ((appName == null) || (appName.length() == 0)) {
41
42 appName = event.getLoggerName();
43 }
44 if (getThreshold() != null) {
45
46 doc.setApplicationName(appName + "." +
47 getThreshold().toString());
48 } else {
49 doc.setApplicationName(appName);
50 }
51 }
52
53
54
55
56 protected Database getDominoDatabase(Session session)
57 throws NotesException {
58
59 Database db = null;
60 String databaseName = doc.getDatabaseName();
61 String serverName = doc.getServerName();
62 if (databaseName == null) {
63 throw new NotesException(0, "Database must be specified");
64 }
65 LogLog.debug("dbPath [" + databaseName + "]");
66 LogLog.debug("Trying to get [" + databaseName + "] on "
67 + (serverName.equals("") ? "local" : serverName));
68 db = session.getDatabase(serverName, databaseName);
69 if (!db.isOpen()) {
70 LogLog.debug("Log databaseName is closed. Trying to open it.");
71 db.open();
72 }
73 return db;
74 }
75
76 /***
77 * Returns the name for a specific appender type.
78 *
79 * @return application path name
80 */
81 abstract String getApplicationPath();
82
83 }