save a reference to log name and pass around internally

This commit is contained in:
Doug MacEachern 2005-09-23 00:11:55 +00:00
parent c0c77a83b3
commit 1bc0ecade2
3 changed files with 17 additions and 6 deletions

View File

@ -107,7 +107,7 @@ static int get_formatted_message(EVENTLOGRECORD *pevlr, char *dllfile,
return 0; return 0;
} }
JNIEXPORT void SIGAR_JNI(win32_EventLog_open) JNIEXPORT void SIGAR_JNI(win32_EventLog_openlog)
(JNIEnv *env, jobject obj, jstring lpSourceName) (JNIEnv *env, jobject obj, jstring lpSourceName)
{ {
HANDLE h; HANDLE h;
@ -164,7 +164,7 @@ JNIEXPORT jint SIGAR_JNI(win32_EventLog_getOldestRecord)
return oldest; return oldest;
} }
JNIEXPORT jobject SIGAR_JNI(win32_EventLog_read) JNIEXPORT jobject SIGAR_JNI(win32_EventLog_readlog)
(JNIEnv *env, jobject obj, jstring jname, jint recordOffset) (JNIEnv *env, jobject obj, jstring jname, jint recordOffset)
{ {
EVENTLOGRECORD *pevlr; EVENTLOGRECORD *pevlr;

View File

@ -18,6 +18,7 @@ public class EventLog extends Win32 {
// Event log timeouts // Event log timeouts
public static final int EVENTLOG_WAIT_INFINITE = -1; public static final int EVENTLOG_WAIT_INFINITE = -1;
private String name;
/** /**
* Create an event log. * Create an event log.
@ -30,7 +31,12 @@ public class EventLog extends Win32 {
* Application, System or Security. * Application, System or Security.
* @exception Win32Exception If opening the event log fails. * @exception Win32Exception If opening the event log fails.
*/ */
public native void open(String lpSourceName) throws Win32Exception; public void open(String name) throws Win32Exception {
this.name = name;
openlog(name);
}
public native void openlog(String name) throws Win32Exception;
/** /**
* Close the event log. * Close the event log.
@ -65,13 +71,18 @@ public class EventLog extends Win32 {
* EVENTLOG_SEEK_READ flag, no sequential reading is currently * EVENTLOG_SEEK_READ flag, no sequential reading is currently
* supported. * supported.
* *
* @param logName The event log name
* @param recordOffset The record offset to read. * @param recordOffset The record offset to read.
* @exception Win32Exception If the event log is not open, or * @exception Win32Exception If the event log is not open, or
* if the specified record could not be * if the specified record could not be
* found * found
*/ */
public native EventLogRecord read(String logName, int recordOffset) public EventLogRecord read(int recordOffset)
throws Win32Exception {
return readlog(this.name, recordOffset);
}
private native EventLogRecord readlog(String name, int recordOffset)
throws Win32Exception; throws Win32Exception;
/** /**

View File

@ -101,7 +101,7 @@ public class EventLogThread implements Runnable {
EventLogRecord record; EventLogRecord record;
try { try {
record = log.read(this.logName, i); record = log.read(i);
} catch (Win32Exception e) { } catch (Win32Exception e) {
logger.error("Unable to read event id " + i + ": " + e); logger.error("Unable to read event id " + i + ": " + e);
continue; continue;