add main method to watch event logs

This commit is contained in:
Doug MacEachern 2005-09-21 22:51:41 +00:00
parent 09f3af2f3e
commit 3b91001651
1 changed files with 47 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package net.hyperic.sigar.win32; package net.hyperic.sigar.win32;
import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -136,4 +138,49 @@ public class EventLogThread implements Runnable {
public void die() { public void die() {
this.shouldDie = true; this.shouldDie = true;
} }
public static void main(String[] args) {
HashMap logs = new HashMap();
if (args.length == 0) {
args = new String[] {
"System", "Application", "Security"
};
}
EventLogNotification watcher =
new EventLogNotification() {
public boolean matches(EventLogRecord record) {
return true;
}
public void handleNotification(EventLogRecord record) {
System.out.println(record);
}
};
for (int i=0; i<args.length; i++) {
String name = args[i];
EventLogThread eventLogThread =
new EventLogThread();
eventLogThread.setLogName(name);
eventLogThread.doStart();
eventLogThread.setInterval(1000);
eventLogThread.add(watcher);
logs.put(name, eventLogThread);
}
System.out.println("Press any key to stop");
try {
System.in.read();
} catch (IOException e) { }
for (Iterator it = logs.values().iterator();
it.hasNext();)
{
EventLogThread eventLogThread =
(EventLogThread)it.next();
eventLogThread.doStop();
}
}
} }