I have been skimming through the Boost.Log tutorials and documentation and in all examples they refer to the "debugger window" or the "debug output window" but I could not find what that is. Is this some sort of standalone application? Where can I download it then?

有帮助吗?

解决方案

Just a guess: This probably means the "output" window of a IDE i.e. of Visual Studios or Eclipses "Output" Window.

其他提示

before you call a boost log method, then make sure you have setup the sink, meaning that you need to call something like this :

static void init_log(void)
{
    /* init boost log
    * 1. Add common attributes
    * 2. set log filter to trace
    */
    boost::log::add_common_attributes();
    boost::log::core::get()->add_global_attribute("Scope",
        boost::log::attributes::named_scope());
    boost::log::core::get()->set_filter(
        boost::log::trivial::severity >= boost::log::trivial::trace
    );

    /* log formatter:
    * [TimeStamp] [ThreadId] [Severity Level] [Scope] Log message
    */
    auto fmtTimeStamp = boost::log::expressions::
        format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S.%f");
    auto fmtThreadId = boost::log::expressions::
        attr<boost::log::attributes::current_thread_id::value_type>("ThreadID");
    auto fmtSeverity = boost::log::expressions::
        attr<boost::log::trivial::severity_level>("Severity");
    auto fmtScope = boost::log::expressions::format_named_scope("Scope",
        boost::log::keywords::format = "%n(%f:%l)",
        boost::log::keywords::iteration = boost::log::expressions::reverse,
        boost::log::keywords::depth = 2);
    boost::log::formatter logFmt =
        boost::log::expressions::format("[%1%] (%2%) [%3%] [%4%] %5%")
        % fmtTimeStamp % fmtThreadId % fmtSeverity % fmtScope
        % boost::log::expressions::smessage;

    /* console sink */
    auto consoleSink = boost::log::add_console_log(std::clog);
    consoleSink->set_formatter(logFmt);

    /* fs sink */
    auto fsSink = boost::log::add_file_log(
        boost::log::keywords::file_name = "test_%Y-%m-%d_%H-%M-%S.%N.log",
        boost::log::keywords::rotation_size = 10 * 1024 * 1024,
        boost::log::keywords::min_free_space = 30 * 1024 * 1024,
        boost::log::keywords::open_mode = std::ios_base::app);
    fsSink->set_formatter(logFmt);
    fsSink->locked_backend()->auto_flush(true);
}

above is a snippet found here: A simple sample of Boost Log

When you want to log something you write something like this :

BOOST_LOG_TRIVIAL(error) << "{ ERROR } Trying to bla bla bla\n";
BOOST_LOG_TRIVIAL(warning) << "{ WARNING } bla bla bla\n";

The output will then be found in your Debug folder when running in debug mode. A file will be created looking like this:

test_2018-04-09_20-08-12.0.log

The output will not be shown in the Debug output window of the Visual Studio

If you do not want to log to a file and just have log in Debug window, then use something like this:

OutputDebugString(L"This is an output");

or add one extra sink in the init_log - like this:

/* setup logging to debugger window */
// Complete sink type
boost::shared_ptr< boost::log::core > core = boost::log::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(boost::log::expressions::is_debugger_present());
core->add_sink(sink);

you also need to add this:

#include <boost/log/sinks/debug_output_backend.hpp>
#include <boost/log/sinks/event_log_backend.hpp>
#include <boost/thread/future.hpp>

typedef boost::log::sinks::synchronous_sink<boost::log::sinks::debug_output_backend> sink_t;

Then output will also be shown in the Debugger window

One of boost.log's sink back-ends is the debugger back end, which uses Windows DebugOutputString function.

A great stand-alone program which displays these messages is SysInternals' DbgView (debug-view), though the IDE(s) generally display them, too.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top