boost::log 输出到 Visual Studio 输出控制台 - 为格式添加额外的 LF/CR
boost::log output to Visual Studio output console - adding extra LF/CR to format
我正在使用boost 1.65.1,我想配置boost::log以将日志消息输出到我的Visual Studio 2015输出调试窗口。 问题是消息具有 unix 行结尾,因此我的所有消息都在输出窗口中的一行(长(行中。
我不想将额外的 CR/LF 添加到每条日志消息中,因为这会使消息的并发输出混淆到我正在使用的文件中。
这就是我初始化 boost::log 以输出 VS 可以接收的消息的方式:
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/sinks/debug_output_backend.hpp>
#include <boost/exception/all.hpp>
#include <exception>
typedef sinks::synchronous_sink< sinks::debug_output_backend > sink_t;
...
logging::add_console_log( <stuff> );
logging::add_file_log( <stuff> );
boost::shared_ptr< logging::core > core = logging::core::get();
// Create the sink. The backend requires synchronization in the frontend.
boost::shared_ptr< sink_t > sink(new sink_t());
// Set the special filter to the frontend
// in order to skip the sink when no debugger is available
sink->set_filter(expr::is_debugger_present());
我在add_file_log和add_console_log中确实有一个格式说明符,但是是否可以添加特定于debug_output_backend的格式说明符以输出我需要的额外 CR/LF。 即仅用于输出到 Visual Studio(其他输出方法保持不变(?
注意:此接收器与 boost::log 文档所称的"控制台"有 100% 不同,后者只是"标准输出"的日志消息目标。
事实证明,
这是一个简单的解决方案。 我在接收器后端文档和 Windows 事件日志接收器部分中进一步阅读,它们使用set_formatter。 所以只需在调用后添加这个set_filter修复它:
sink->set_formatter
(
expr::format("%1%: [%2%] - %3%rn")
% expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S")
% logging::trivial::severity
% expr::smessage
);
希望这对某人有所帮助。
相关文章:
- 如何调用继承的重载运算符<<并在派生类的输出中添加更多文本?
- C++添加到字符串(输出)
- C++:添加到输出中的不需要的数字
- 输出操纵器 std::ends 是否向输出缓冲区添加空字符?
- 为什么我添加一个"&",它输出不同?
- boost::log 输出到 Visual Studio 输出控制台 - 为格式添加额外的 LF/CR
- 在我的桌子上仍将其添加到我的桌子的同时,我如何为我的输出添加一个额外的零
- 在我的输出之前,我该如何添加数字
- 使用C 将JPG文件添加到输出的HTML文件中
- 为什么 std::cout 在我的输出中添加返回或换行符
- 如何将项目添加到输出文件中
- 如何使用Coin3d / OpenInventor添加任意数量的引擎输出
- Windows Batch - 如何在将标准输出重定向到文件时添加时间戳
- 添加 cout 语句会更正输出
- 添加尾随空格和使用 eof 时的额外输出
- C++输出错误(添加了新问题)
- 如何在不破坏现有代码的情况下将输出参数添加到功能
- 对于MySQLDump,添加一个注释,输出每个表转储的行数
- 在Visual C++中使用MessageBoxW来输出添加在一起的多个字符串
- Ndk-build输出添加符号错误.文件格式错误