Search code examples
c++boostbackwards-compatibilityboost-log

Boost Log 1.62: filter condition must be in parentheses?


I'm working with the Boost Log library on Ubuntu 14.04 and Ubuntu 18.04. On 14.04, I'm using libboost-log1.54, while on 18.04 I'm using libboost-log1.62.

I'm using the following example code (called main.cpp):

#include <boost/log/utility/setup.hpp>

int main(int argc, char * argv[])
{
  boost::log::settings s;
  s["Core"]["DisableLogging"] = false;
  s["Sinks.File.Destination"] = "TextFile";
  s["Sinks.File.FileName"] = "test.log";
  s["Sinks.File.Filter"] = "not %Channel% matches Something";

  boost::log::init_from_settings(s);

  return 0;
}

I'm using this command to build the code:

g++ main.cpp -DBOOST_LOG_DYN_LINK -lboost_log_setup -lboost_system

The code can be built successfully on both 14.04 and 18.04. However, when I ran the executable file, the 18.04 one threw an exception:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::log::v2_mt_posix::parse_error> >'
  what():  Invalid filter definition: unexpected character encountered
Aborted (core dumped)

In order to fix this, I need to modify the "Sinks.File.Filter" line to this:

s["Sinks.File.Filter"] = "not (%Channel% matches Something)";

That is: put the condition part in a pair of parentheses.

Why do I have to put the condition in the parentheses? This looks like a breaking change because what can run using Boost 1.54 can no longer run using Boost 1.62. I read through the documentation and the changelog but didn't find anything that seemingly related. The only possibly related change was in 1.55 in which the change log says:

Rewritten some of the parsers to reduce the compiled binary size. The rewritten parsers are more robust in detecting ambiguous and incorrect input.

So my questions are:

  • Am I doing it correctly? Did I miss something?
  • Which version of Boost Log was this breaking change introduced?

Solution

  • Am I doing it correctly? Did I miss something?

    Yes, putting the condition in the parenthesis is the correct solution. The rationale is that otherwise the syntax is ambiguous because the "not %Channel%" part is a valid filter in itself, which tests for the Channel attribute absence.

    Which version of Boost Log was this breaking change introduced?

    As you've found out, 1.55 was the first release with rewritten and more robust parsers. Earlier releases were less strict, but should accept the syntax that is accepted by the new parsers.