Search code examples
c++boostboost-log

Combining filters in boost log


I use boost log and want to define a composed filter. I use boost::log::init_from_streamto read the configuration from a stream. Filtering on single conditions works fine. I can do

Filter = "%Channel% = A"

to get only log entries from channel A. I can do

Filter = "%Severity% >= warn"

to get only log entries that have a severity which is warning or above.

Here comes the question: I want to do someting like

Filter = "   (%Channel% = A AND %Severity% >= warn)
          OR (%Channel% = B AND %Severity% >= info)"

I was not able to find any documentation regarding such a combination of filters. Is there a way to do this when using boost::log::init_from_stream?


Solution

  • I've found this documentation page which documents the grammar:

    • Filter and formatter parsers

      filter:
          condition { op condition }
      
      op:
          &
          and
          |
          or
      
      condition:
          !condition
          not condition
          (filter)
          %attribute_name%
          %attribute_name% relation operand
      
      relation:
          >
          <
          =
          !=
          >=
          <=
          begins_with
          ends_with
          contains
          matches
      

    Using this, the example given in the question can be expressed as follows:

    Filter = "(%Channel% = A & %Severity% >= warn) | (%Channel% = B & %Severity% >= info)"