How to redirect Boost.Log to file

前端 未结 1 1104
孤城傲影
孤城傲影 2021-02-07 10:18

I want a simple log file in a concurrent application. I\'ve download Boost.Log v2.0 and using compiled it with Boost 1.53.0.

The problem is th

相关标签:
1条回答
  • 2021-02-07 10:29

    You can make BOOST_LOG_TRIVIAL use a file with (assuming that namespace logging = boost::log;:

    #include <boost/log/core.hpp>
    #include <boost/log/trivial.hpp>
    #include <boost/log/expressions.hpp>
    #include <boost/log/utility/setup/file.hpp>
    
    void init()
    {
        logging::add_file_log("sample.log");
    
        logging::core::get()->set_filter
        (
            logging::trivial::severity >= logging::trivial::info
        );
    }
    

    And in main:

    int main(int, char*[])
    {
        init();
    
        BOOST_LOG_TRIVIAL(trace) << "A trace severity message";
     // other types of severity
        BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message";
    
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题