Boost Log 1.62:过滤条件必须在括号内?
Boost Log 1.62: filter condition must be in parentheses?
我在 Ubuntu 14.04 和 Ubuntu 18.04 上使用 Boost Log 库。在 14.04,我使用 libboost-log1.54
,而在 18.04,我使用 libboost-log1.62
.
我正在使用以下示例代码(称为 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;
}
我正在使用此命令构建代码:
g++ main.cpp -DBOOST_LOG_DYN_LINK -lboost_log_setup -lboost_system
代码在14.04和18.04上都可以编译成功。但是,当我运行可执行文件时,18.04抛出一个异常:
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)
为了解决这个问题,我需要将 "Sinks.File.Filter" 行修改为:
s["Sinks.File.Filter"] = "not (%Channel% matches Something)";
即:将condition
部分放在一对括号内。
为什么我必须把条件放在括号里?这看起来像是一个重大变化,因为使用 Boost 1.54 可以 运行 的东西不能再使用 Boost 1.62 运行 了。我通读了 documentation and the changelog
但没有发现任何看似相关的内容。唯一可能相关的更改是在 1.55
中,其中更改日志显示:
Rewritten some of the parsers to reduce the compiled binary size. The rewritten parsers are more robust in detecting ambiguous and incorrect input.
所以我的问题是:
- 我做得对吗?我错过了什么吗?
- 此重大更改引入了哪个版本的 Boost Log?
Am I doing it correctly? Did I miss something?
是的,将条件放在括号中是正确的解决方案。基本原理是否则语法不明确,因为 "not %Channel%" 部分本身是一个有效的过滤器,它测试 Channel 属性是否缺失。
Which version of Boost Log was this breaking change introduced?
如您所知,1.55 是第一个具有重写且更强大的解析器的版本。早期版本不太严格,但应该接受新解析器接受的语法。
我在 Ubuntu 14.04 和 Ubuntu 18.04 上使用 Boost Log 库。在 14.04,我使用 libboost-log1.54
,而在 18.04,我使用 libboost-log1.62
.
我正在使用以下示例代码(称为 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;
}
我正在使用此命令构建代码:
g++ main.cpp -DBOOST_LOG_DYN_LINK -lboost_log_setup -lboost_system
代码在14.04和18.04上都可以编译成功。但是,当我运行可执行文件时,18.04抛出一个异常:
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)
为了解决这个问题,我需要将 "Sinks.File.Filter" 行修改为:
s["Sinks.File.Filter"] = "not (%Channel% matches Something)";
即:将condition
部分放在一对括号内。
为什么我必须把条件放在括号里?这看起来像是一个重大变化,因为使用 Boost 1.54 可以 运行 的东西不能再使用 Boost 1.62 运行 了。我通读了 documentation and the changelog
但没有发现任何看似相关的内容。唯一可能相关的更改是在 1.55
中,其中更改日志显示:
Rewritten some of the parsers to reduce the compiled binary size. The rewritten parsers are more robust in detecting ambiguous and incorrect input.
所以我的问题是:
- 我做得对吗?我错过了什么吗?
- 此重大更改引入了哪个版本的 Boost Log?
Am I doing it correctly? Did I miss something?
是的,将条件放在括号中是正确的解决方案。基本原理是否则语法不明确,因为 "not %Channel%" 部分本身是一个有效的过滤器,它测试 Channel 属性是否缺失。
Which version of Boost Log was this breaking change introduced?
如您所知,1.55 是第一个具有重写且更强大的解析器的版本。早期版本不太严格,但应该接受新解析器接受的语法。