提升::日志 - 使用严重性和自定义过滤器属性记录?要使用的宏
Boost::Log - Log with severity and custom filter attribute? Which macro(s) to use?
我想使用 boost::log 让我的负载测试应用程序记录到不同的文件和控制台。每个工作线程(代表连接到要测试的服务器的一个用户)应记录线程日志并将失败的调用记录到失败的调用日志中。我尝试通过使用过滤器来实现这一点。
目标是:
=> All logs with severity = lower than "INFO" will be discarded
=> All log records having the attribute "global" go to ./logs/loadtest.log AND to console
=> All log records having the attribute "thread" go to ./logs/thread.log AND to console
=> All log records having the attribute "faileCalls" go to ./logs/failedCalls.log AND to console
这是我的初始化代码:
void initLogging()
{
boost::shared_ptr<boost::log::core::basic_core> core = boost::log::core::get();
// Construct the sinks for our global log file and for console
typedef boost::log::sinks::asynchronous_sink<boost::log::sinks::text_ostream_backend> text_sink;
// global log file
boost::shared_ptr<text_sink> sinkLoadtest = boost::make_shared<text_sink>();
sinkLoadtest->locked_backend()->add_stream(boost::make_shared<std::ofstream>("./logs/loadtest.log", std::ios::app));
sinkLoadtest->locked_backend()->auto_flush(true);
sinkLoadtest->set_filter(boost::log::filters::has_attr("global"));
core->add_sink(sinkLoadtest);
// console
boost::shared_ptr<text_sink> sinkConsole = boost::make_shared<text_sink>();
boost::shared_ptr<std::ostream> stream(&std::clog, boost::log::empty_deleter());
sinkConsole->locked_backend()->add_stream(stream);
sinkConsole->locked_backend()->auto_flush(true);
core->add_sink(sinkConsole);
// thread dependent logging (one file per workthread)
sinkThread = boost::make_shared<text_sink>();
sinkFailedCalls = boost::make_shared<text_sink>();
sinkThread->locked_backend()->add_stream(boost::make_shared<std::ofstream>("./logs/thread.log"), std::ios::app));
sinkFailedCalls->locked_backend()->add_stream(boost::make_shared<std::ofstream>("./logs/failedCalls.log", std::ios::app));
sinkThread->set_filter(boost::log::filters::has_attr("thread"));
sinkFailedCalls->set_filter(boost::log::filters::has_attr("failedCalls"));
core->add_sink(sinkThread);
core->add_sink(sinkFailedCalls);
// set global severity level
core->set_filter(boost::log::filters::attr<boost::log::trivial::severity_level>("Severity") >= boost::log::trivial::info);
}
这些是我的问题:使用哪个宏才能传递严重性级别以及我的自定义筛选器属性之一?
遮挡记录器的最佳方法是什么?Alwas从核心获取它还是有一个成员变量"记录器"?我需要它是线程安全的。
提前感谢您的努力!
最好一月
//编辑:如果这样的宏可以提供使用流运算符,那就太好
您必须使用 BOOST_LOG_STREAM_WITH_PARAMS 或等效BOOST_LOG_WITH_PARAMS
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++概念:如何使用'concept'检查模板化结构的属性?
- 将两个数组中的差异记录在第三个数组中
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- C++如何将同一类的实例作为属性
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- boost::log 设置"Channel"通道记录器中的属性
- MSBUILD -TAG PropertyGroup具有属性标签,但没有记录
- boost属性树解析json后无法检索记录
- 提升::日志 - 使用严重性和自定义过滤器属性记录?要使用的宏
- 提升日志记录类属性