【发布时间】:2018-01-13 17:28:23
【问题描述】:
我正在使用 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% 的不同,后者只是“标准输出”的日志消息目的地。
【问题讨论】:
-
我不知道如何在 Boost 中解决这个问题,但归根结底必须是
fopen调用。以“文本”模式打开文件(将“t”添加到模式字符串)解决了这个问题。 -
根本不是重复的。控制台本质上是 cout。 Windows 控制台是一个完全不同的输出“目的地”。它在 boost::log 中有自己的接收器,就像 cout 一样。
标签: c++ visual-studio boost