systemd journal watcher daemon in ruby
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
471 B

  1. module JournaldWatcher
  2. class Listener
  3. def initialize(journal, filter)
  4. @journal = journal
  5. @filter = filter
  6. end
  7. def listen(&block)
  8. @journal.filter @filter
  9. @journal.seek :tail
  10. watch { |entry| block.call(entry) }
  11. end
  12. private
  13. # like Systemd::Journal.watch but don't wait forever
  14. def watch
  15. loop { (yield @journal.current_entry while @journal.move_next) if @journal.wait(100_000) }
  16. end
  17. end
  18. end