Add EventLog.getLogNames() method

This commit is contained in:
Doug MacEachern 2007-01-19 01:42:57 +00:00
parent 3981cadde4
commit 82f7664068
3 changed files with 42 additions and 8 deletions

View File

@ -1,3 +1,7 @@
2007-01-18 Doug MacEachern <dougm@hyperic.com>
* Add EventLog.getLogNames() method
2007-01-17 Doug MacEachern <dougm@hyperic.com>
* Various fixes for sparc64

View File

@ -117,4 +117,31 @@ public class EventLog extends Win32 {
*/
public native void waitForChange(int timeout)
throws Win32Exception;
/**
* Eventlog names are store in the registry under:
* SYSTEM\CurrentControlSet\Services\Eventlog
* This method returns the list of these entries.
* @return All Eventlog names
*/
public static String[] getLogNames() {
final String EVENTLOG_KEY =
"SYSTEM\\CurrentControlSet\\Services\\Eventlog";
String[] names;
RegistryKey key = null;
try {
key = RegistryKey.LocalMachine.openSubKey(EVENTLOG_KEY);
names = key.getSubKeyNames();
} catch (Win32Exception e) {
names =
new String[] { SYSTEM, APPLICATION, SECURITY };
} finally {
if (key != null) {
key.close();
}
}
return names;
}
}

View File

@ -93,21 +93,27 @@ public class TestEventLog extends SigarTestCase {
}
private boolean readAll(String logname) throws Exception {
int fail = 0, success = 0;
int fail = 0, success = 0, max = 500;
String testMax = System.getProperty("sigar.testeventlog.max");
if (testMax != null) {
max = Integer.parseInt(testMax);
}
EventLogRecord record;
EventLog log = new EventLog();
log.open(logname);
int oldestRecord = log.getOldestRecord();
int numRecords = log.getNumberOfRecords();
traceln("oldest=" + oldestRecord + ", total=" + numRecords);
traceln("oldest=" + oldestRecord +
", total=" + numRecords +
", max=" + max);
for (int i = oldestRecord; i < oldestRecord + numRecords; i++) {
try {
record = log.read(i);
success++;
if (!getVerbose() && (success > 500)) {
break; //read plenty
if (success > max) {
break;
}
} catch (Win32Exception e) {
fail++;
@ -124,10 +130,7 @@ public class TestEventLog extends SigarTestCase {
// Test reading all records
public void testRead() throws Exception {
String[] logs = {
EventLog.SYSTEM,
EventLog.APPLICATION
};
String[] logs = EventLog.getLogNames();
for (int i=0; i<logs.length; i++) {
String msg = "readAll(" + logs[i] + ")";
traceln(msg);