【发布时间】:2018-11-07 20:57:39
【问题描述】:
我正在 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 和changelog,但没有找到任何看似相关的内容。唯一可能相关的更改是1.55,其中更改日志显示:
重写了一些解析器以减少编译后的二进制大小。重写后的解析器在检测歧义和错误输入方面更加稳健。
所以我的问题是:
- 我做得对吗?我错过了什么吗?
- 此重大更改引入了哪个版本的 Boost Log?
【问题讨论】:
标签: c++ boost backwards-compatibility boost-log