Module: Systemd::Journal::Filterable
- Included in:
- Systemd::Journal
- Defined in:
- lib/systemd/journal/filterable.rb
Instance Method Summary collapse
-
#add_conjunction ⇒ nil
Add an AND condition to the filter.
-
#add_disjunction ⇒ nil
Add an OR condition to the filter.
-
#add_filter(field, value) ⇒ nil
Add a filter to journal, such that only entries where the given filter matches are returned.
-
#add_filters(filters) ⇒ Object
Add a set of filters to the journal, such that only entries where the given filters match are returned.
-
#clear_filters ⇒ nil
Remove all filters and conjunctions/disjunctions.
-
#filter(*conditions) ⇒ Object
Filter the journal at a high level.
Instance Method Details
#add_conjunction ⇒ nil
Add an AND condition to the filter. All previously added terms will be ANDed together with terms following the conjunction. Navigable#move_next or Navigable#move_previous must be invoked after adding a match before attempting to read from the journal.
94 95 96 97 98 99 |
# File 'lib/systemd/journal/filterable.rb', line 94 def add_conjunction @reopen_filter_conditions << :conjunction rc = Native.sd_journal_add_conjunction(@ptr) raise JournalError, rc if rc < 0 end |
#add_disjunction ⇒ nil
Add an OR condition to the filter. All previously added matches will be ORed with the terms following the disjunction. Navigable#move_next or Navigable#move_previous must be invoked after adding a match before attempting to read from the journal.
74 75 76 77 78 79 |
# File 'lib/systemd/journal/filterable.rb', line 74 def add_disjunction @reopen_filter_conditions << :disjunction rc = Native.sd_journal_add_disjunction(@ptr) raise JournalError, rc if rc < 0 end |
#add_filter(field, value) ⇒ nil
Add a filter to journal, such that only entries where the given filter matches are returned. Navigable#move_next or Navigable#move_previous must be invoked after adding a filter before attempting to read from the journal.
38 39 40 41 42 43 44 |
# File 'lib/systemd/journal/filterable.rb', line 38 def add_filter(field, value) @reopen_filter_conditions << {field => value} match = "#{field.to_s.upcase}=#{value}" rc = Native.sd_journal_add_match(@ptr, match, match.length) raise JournalError, rc if rc < 0 end |
#add_filters(filters) ⇒ Object
Add a set of filters to the journal, such that only entries where the given filters match are returned.
54 55 56 57 58 |
# File 'lib/systemd/journal/filterable.rb', line 54 def add_filters(filters) filters.each do |field, value| Array(value).each { |v| add_filter(field, v) } end end |
#clear_filters ⇒ nil
Remove all filters and conjunctions/disjunctions.
103 104 105 106 107 |
# File 'lib/systemd/journal/filterable.rb', line 103 def clear_filters @reopen_filter_conditions = [] Native.sd_journal_flush_matches(@ptr) end |
#filter(*conditions) ⇒ Object
Filter the journal at a high level. Takes any number of arguments; each argument should be a hash representing a condition to filter based on. Fields inside the hash will be ANDed together. Each hash will be ORed with the others. Fields in hashes with Arrays as values are treated as an OR statement, since otherwise they would never match.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/systemd/journal/filterable.rb', line 20 def filter(*conditions) clear_filters last_index = conditions.length - 1 conditions.each_with_index do |condition, index| add_filters(condition) add_disjunction unless index == last_index end end |