Boost.Log:如何按当前线程 ID 进行过滤
Boost.Log: how to filter by current thread id
我正在使用Boost.Log,它是Boost v1.54的一部分。我有一个接收器,我只想接受来自当前线程的日志消息。我怎样才能做到这一点?
BOOST_LOG_ATTRIBUTE_KEYWORD(thread_id, "ThreadID", logging::attributes::current_thread_id::value_type)
std::stringstream stream;
logging::add_common_attributes();
boost::shared_ptr<text_sink> sink = boost::make_shared<text_sink>();
sink->locked_backend()->add_stream(stream);
logging::core::get()->add_sink(sink);
boost::thread::id currentThreadId = boost::this_thread::get_id();
// At this line compiler complains about the '==' operator.
sink->set_filter(thread_id == currentThreadId);
没有最后一行,一切正常,当我配置接收器格式化程序时,它会输出调用线程 ID。将thread_id属性与当前线程 ID 进行比较的正确方法是什么?我知道我可以使用一些自定义属性来标记具有当前线程 ID 的消息,然后按该属性过滤它们,但是默认 boost 的 current_thread_id 属性呢?它可用于此目的吗?
好吧
,在花了半个晚上四处挖掘之后,我遇到了(无证? boost::log::aux
命名空间,我在其中找到了boost::log::aux::this_thread::get_id()
函数。它返回一个正确类型的对象,我现在能够将其与 thread_id
关键字进行比较。现在我想知道 boost::log::aux
命名空间是否仅用于内部使用?前段时间,我曾经使用boost互斥锁/锁的一些内部功能,在下一次库更新后,它们更改了所有内容,我什至无法针对新版本的库编译代码。所以现在我不想重蹈覆辙:)
相关文章:
- 从函数角度看ID到文件路径的内部与外部映射
- 通过组合不同的类型来创建唯一的id
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- FFMPEG配置文件级别id大小无效
- 方法内部但循环仍得到预期的不合格id错误C++
- 如何获取 GLFW 窗口 ID?
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 显示数组中的学生 ID 和最高分
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- 在PostgreSQL中根据它们的ID选择大量行的最快方法是什么?
- Xcode 9.4.1 中的 Apple Mach-O 链接器 (id) 错误
- 错误:令牌 { '{' 之前应存在非限定 ID
- 为什么 gcc 会给我可能未初始化的警告 deque::insert 带有过滤范围
- 断言"id < 0"在Qt ActiveX中失败
- C++部分概念 id:显式模板规范顺序/第一个参数的特殊状态的原因是什么?
- 如何根据两个因素组织向量:id 和数量?(C++)
- 在返回 0 之前应为非限定 ID
- Direct3D 11 - HLSL - 获取顶点索引 ID
- 编译时检查特征专用化是否具有唯一 ID
- Boost.Log:如何按当前线程 ID 进行过滤