example/tailing.rb in winevt_c-0.5.0 vs example/tailing.rb in winevt_c-0.5.1
- old
+ new
@@ -1,22 +1,13 @@
require 'winevt'
-require 'rexml/document'
@subscribe = Winevt::EventLog::Subscribe.new
@subscribe.tail = true
-@subscribe.subscribe("Security", "*[System[(Level <= 4) and TimeCreated[timediff(@SystemTime) <= 86400000]]]")
-while (1) do
- if @subscribe.next
- eventlog = @subscribe.render
- message = @subscribe.message
- string_inserts = @subscribe.string_inserts
- message = message.gsub(/(%\d+)/, '\1$s')
- message = sprintf(message, *string_inserts)
-
+@subscribe.subscribe(
+ "Security", "*[System[(Level <= 4) and TimeCreated[timediff(@SystemTime) <= 86400000]]]"
+)
+while true do
+ @subscribe.each do |eventlog, message, string_inserts|
puts ({eventlog: eventlog, data: message})
- @subscribe.close_handle # Dispose EVT_HANDLE variable which is allocated in EvtNext
- else
- printf(".")
- sleep(1)
end
+ sleep(1)
end
-puts @subscribe.bookmark