Module: Systemd::Journal::Navigable
- Included in:
- Systemd::Journal
- Defined in:
- lib/systemd/journal/navigable.rb
Instance Method Summary collapse
-
#cursor ⇒ String
returns a string representing the current read position.
-
#cursor?(c) ⇒ Boolean
Check if the read position is currently at the entry represented by the provided cursor value.
-
#move(offset = 1) ⇒ Integer
Move the read pointer by ‘offset` entries.
-
#move_next ⇒ Boolean
Move the read pointer to the next entry in the journal.
-
#move_next_skip(amount) ⇒ Integer
Move the read pointer forward by ‘amount` entries.
-
#move_previous ⇒ Boolean
Move the read pointer to the previous entry in the journal.
-
#move_previous_skip(amount) ⇒ Integer
Move the read pointer backwards by ‘amount` entries.
-
#seek(where) ⇒ True
Seek to a position in the journal.
Instance Method Details
#cursor ⇒ String
10 11 12 13 14 15 16 17 |
# File 'lib/systemd/journal/navigable.rb', line 10 def cursor out_ptr = FFI::MemoryPointer.new(:pointer, 1) if (rc = Native.sd_journal_get_cursor(@ptr, out_ptr)) < 0 raise JournalError, rc end Journal.read_and_free_outstr(out_ptr.read_pointer) end |
#cursor?(c) ⇒ Boolean
Check if the read position is currently at the entry represented by the provided cursor value. provided cursor, False otherwise.
24 25 26 27 28 29 30 |
# File 'lib/systemd/journal/navigable.rb', line 24 def cursor?(c) if (rc = Native.sd_journal_test_cursor(@ptr, c)) < 0 raise JournalError, rc end rc > 0 end |
#move(offset = 1) ⇒ Integer
Move the read pointer by ‘offset` entries.
37 38 39 |
# File 'lib/systemd/journal/navigable.rb', line 37 def move(offset = 1) (offset > 0) ? move_next_skip(offset) : move_previous_skip(-offset) end |
#move_next ⇒ Boolean
Move the read pointer to the next entry in the journal.
45 46 47 48 49 50 51 |
# File 'lib/systemd/journal/navigable.rb', line 45 def move_next with_auto_reopen { rc = Native.sd_journal_next(@ptr) raise JournalError, rc if rc < 0 rc > 0 } end |
#move_next_skip(amount) ⇒ Integer
Move the read pointer forward by ‘amount` entries.
57 58 59 60 61 62 63 |
# File 'lib/systemd/journal/navigable.rb', line 57 def move_next_skip(amount) with_auto_reopen { rc = Native.sd_journal_next_skip(@ptr, amount) raise JournalError, rc if rc < 0 rc } end |
#move_previous ⇒ Boolean
Move the read pointer to the previous entry in the journal.
69 70 71 72 73 74 75 |
# File 'lib/systemd/journal/navigable.rb', line 69 def move_previous with_auto_reopen { rc = Native.sd_journal_previous(@ptr) raise JournalError, rc if rc < 0 rc > 0 } end |
#move_previous_skip(amount) ⇒ Integer
Move the read pointer backwards by ‘amount` entries.
81 82 83 84 85 86 87 |
# File 'lib/systemd/journal/navigable.rb', line 81 def move_previous_skip(amount) with_auto_reopen { rc = Native.sd_journal_previous_skip(@ptr, amount) raise JournalError, rc if rc < 0 rc } end |
#seek(where) ⇒ True
Seek to a position in the journal. Note: after seeking, you must call #move_next or #move_previous
before you can call {#read_field} or {#current_entry}.
When calling `seek(:tail)` the read pointer is positioned _after_
the last entry in the journal -- thus you should use `move_previous`.
Otherwise, use `move_next`.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/systemd/journal/navigable.rb', line 108 def seek(where) rc = if [:head, :start].include?(where) Native.sd_journal_seek_head(@ptr) elsif [:tail, :end].include?(where) Native.sd_journal_seek_tail(@ptr) elsif where.is_a?(Time) Native.sd_journal_seek_realtime_usec( @ptr, where.to_i * 1_000_000 ) elsif where.is_a?(String) Native.sd_journal_seek_cursor(@ptr, where) else raise ArgumentError, "Unknown seek type: #{where.class}" end raise JournalError, rc if rc < 0 true end |