Add EventLog.getLogNames() method
This commit is contained in:
		
							parent
							
								
									3981cadde4
								
							
						
					
					
						commit
						82f7664068
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user