Method: Systemd::Journal::Filterable#filter

Defined in:
lib/systemd/journal/filterable.rb

#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.

Examples:

j = Systemd::Journal.filter(
  {_systemd_unit: 'session-4.scope'},
  {priority: [4, 6]},
  {_exe: '/usr/bin/sshd', priority: 1}
)
# equivalent to
(_systemd_unit == 'session-4.scope') ||
(priority == 4 || priority == 6)     ||
(_exe == '/usr/bin/sshd' && priority == 1)

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