c++ - boost.log 含义和作用

标签 c++ logging boost

我正在编写将 Python 应用程序转换为 C++ 的代码。
我现在正在做日志。
我使用 boost log ..但我发现有些事情真的很难理解
我正在尝试为我的代码的每个部分制作单独的文件,以便主要功能保持干净。

当我使用 boost log 执行此操作时,一切正常但定义
“或声明或初始化……这三个词对于内置类型很容易理解,但在使用库类时很难知道它的含义……或者可能是我的大脑不适合学习编程”
在记录器文件中定义记录器在主文件中看不到“虽然当我在主文件中定义记录器但其他组件如接收器和主文件外部的核心一切顺利

只是我想知道为什么我必须在 main 中定义记录器,尽管所有其他组件都在 main 之外定义?
这与新的“我真的尽量避免内存安排因为我非常害怕被困在那里”有关吗

我正在编辑问题以更清楚地显示问题
在 c++2.cpp 中,我创建函数 init_logger() 返回 void
在这个函数中,我定义了接收器、核心、属性,它们在从函数返回后持续存在“为什么它们持续存在??”

//make attribute argument
BOOST_LOG_ATTRIBUTE_KEYWORD(a_channel, "Channel", std::string)//????????????
void init_file_collecting(boost::shared_ptr< file_sink > sink)
{
    sink->locked_backend()->set_file_collector(sinks::file::make_collector(
        keywords::target = "logs",                      /*< the target directory >*/
        keywords::max_size = 16 * 1024 * 1024,          /*< maximum total size of the stored files, in bytes >*/
        keywords::min_free_space = 100 * 1024 * 1024,   /*< minimum free space on the drive, in bytes >*/
        keywords::max_files = 7                       /*< maximum number of stored files >*/
    ));
}

boost::shared_ptr< logging::core > core = logging::core::get();
    /*
    src::channel_logger<std::string> lg_chan_0(keywords::channel = "0");
    src::channel_logger<std::string> lg_chan_1(keywords::channel = "1");
    src::channel_logger<std::string> lg_chan_2(keywords::channel = "2");
    src::channel_logger<std::string> lg_chan_3(keywords::channel = "3");
    src::channel_logger<std::string> lg_chan_4(keywords::channel = "4");
    src::channel_logger<std::string> lg_chan_5(keywords::channel = "5");
    src::channel_logger<std::string> lg_chan_6(keywords::channel = "6");
    */
    core->add_global_attribute("ThreadID", boost::log::attributes::current_thread_id());
    core->add_global_attribute("TimeStamp",attrs::local_clock());
    core->add_global_attribute("RecordID", attrs::counter< unsigned int >(1));
    logging::add_common_attributes();

    //lg_chan_0(keywords::channel = "net");

    // Create a text file sink
    boost::shared_ptr< file_sink > sink0(new file_sink(
        keywords::file_name = "first_date_with_404.log",
        keywords::rotation_size = 16384
    ));
sink0->set_filter(expr::attr< std::string >("Channel") == "0");
init_file_collecting(sink0);
sink0->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );
core->add_sink(sink0);

但是当我在 init_function() 中定义记录器时,它们在返回后不会持续存在,编译器告诉我它们未定义
为什么 core 和 sinks 在返回后仍然存在并且可以被 c++2.cpp 中定义的 logmacros 使用但记录器不存在?

    /*
    src::channel_logger<std::string> lg_chan_0(keywords::channel = "0");
    src::channel_logger<std::string> lg_chan_1(keywords::channel = "1");
    src::channel_logger<std::string> lg_chan_2(keywords::channel = "2");
    src::channel_logger<std::string> lg_chan_3(keywords::channel = "3");
    src::channel_logger<std::string> lg_chan_4(keywords::channel = "4");
    src::channel_logger<std::string> lg_chan_5(keywords::channel = "5");
    src::channel_logger<std::string> lg_chan_6(keywords::channel = "6");
    */

代码如下:

c++2.cpp

// c++2.cpp : Defines the entry point for the console application.


#include "stdafx.h"
#include "program_options_1.h"
#include "utils_logger.h"


int main(int argc, char* argv[])
{
    //1 init program_options and configure it
    po::variables_map vm =init_program_options(argc, argv);
    //2 init logger and configure it
    init_logging();
    //3

    src::channel_logger<std::string> lg_chan_0(keywords::channel = "0");
    src::channel_logger<std::string> lg_chan_1(keywords::channel = "1");
    src::channel_logger<std::string> lg_chan_2(keywords::channel = "2");
    src::channel_logger<std::string> lg_chan_3(keywords::channel = "3");
    src::channel_logger<std::string> lg_chan_4(keywords::channel = "4");
    src::channel_logger<std::string> lg_chan_5(keywords::channel = "5");
    src::channel_logger<std::string> lg_chan_6(keywords::channel = "6");

    BOOST_LOG(lg_chan_0) << "Hello world0!";
    BOOST_LOG(lg_chan_1) << "Hello world1!";
    BOOST_LOG(lg_chan_2) << "Hello world2!";
    BOOST_LOG(lg_chan_3) << "Hello world3!";
    BOOST_LOG(lg_chan_4) << "Hello world4!";
    BOOST_LOG(lg_chan_5) << "Hello world5!";
    BOOST_LOG(lg_chan_6) << "Hello world6!";
    return 0;
}

utils_logger.h

#pragma once
/*
*          Copyright Andrey Semashev 2007 - 2015.
* Distributed under the Boost Software License, Version 1.0.
*    (See accompanying file LICENSE_1_0.txt or copy at
*          http://www.boost.org/LICENSE_1_0.txt)
*/

#include <stdexcept>
#include <string>
#include <iostream>
#include <fstream>

#include <boost/smart_ptr/shared_ptr.hpp>

#include <boost/core/null_deleter.hpp>

#include <boost/lambda/lambda.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/log/attributes/current_thread_id.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/expressions/formatters/format.hpp>

#include <boost/log/core.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>

#include <boost/log/common.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/logger.hpp>

namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords;
/*
1-first date with 404
2-first date with 200
3-dates with zero size after first date with 200
4-dates of saturday and sunday after first date with 200
5-dates not saturday or sunday after first date with 200 and having zero size
6-dates not saturday or sunday after first date with 200 and having 400
7-last date recieved and written to file

*/
//make attribute argument
BOOST_LOG_ATTRIBUTE_KEYWORD(a_channel, "Channel", std::string)//????????????

// Complete sink type
typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;

//[ example_sinks_xml_file_collecting
void init_file_collecting(boost::shared_ptr< file_sink > sink)
{
    sink->locked_backend()->set_file_collector(sinks::file::make_collector(
        keywords::target = "logs",                      /*< the target directory >*/
        keywords::max_size = 16 * 1024 * 1024,          /*< maximum total size of the stored files, in bytes >*/
        keywords::min_free_space = 100 * 1024 * 1024,   /*< minimum free space on the drive, in bytes >*/
        keywords::max_files = 7                       /*< maximum number of stored files >*/
    ));
}
//]

#if 0
//[ example_sinks_xml_file
// Complete file sink type
typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;

void write_header(sinks::text_file_backend::stream_type& file)
{
    file << "<?xml version=\"1.0\"?>\n<log>\n";
}

void write_footer(sinks::text_file_backend::stream_type& file)
{
    file << "</log>\n";
}

void init_logging()
{
    // Create a text file sink
    boost::shared_ptr< file_sink > sink(new file_sink(
        keywords::file_name = "%Y%m%d_%H%M%S_%5N.xml",  /*< the resulting file name pattern >*/
        keywords::rotation_size = 16384                 /*< rotation size, in characters >*/
    ));

    sink->set_formatter
    (
        expr::format("\t<record id=\"%1%\" timestamp=\"%2%\">%3%</record>")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::xml_decor[expr::stream << expr::smessage]            /*< the log message has to be decorated, if it contains special characters >*/
    );

    // Set header and footer writing functors
    sink->locked_backend()->set_open_handler(&write_header);
    sink->locked_backend()->set_close_handler(&write_footer);

    // Add the sink to the core
    logging::core::get()->add_sink(sink);
}
//]
#endif

//[ example_sinks_xml_file_final
void init_logging()
{
    boost::shared_ptr< logging::core > core = logging::core::get();
    /*
    src::channel_logger<std::string> lg_chan_0(keywords::channel = "0");
    src::channel_logger<std::string> lg_chan_1(keywords::channel = "1");
    src::channel_logger<std::string> lg_chan_2(keywords::channel = "2");
    src::channel_logger<std::string> lg_chan_3(keywords::channel = "3");
    src::channel_logger<std::string> lg_chan_4(keywords::channel = "4");
    src::channel_logger<std::string> lg_chan_5(keywords::channel = "5");
    src::channel_logger<std::string> lg_chan_6(keywords::channel = "6");
    */
    core->add_global_attribute("ThreadID", boost::log::attributes::current_thread_id());
    core->add_global_attribute("TimeStamp",attrs::local_clock());
    core->add_global_attribute("RecordID", attrs::counter< unsigned int >(1));
    logging::add_common_attributes();

    //lg_chan_0(keywords::channel = "net");

    // Create a text file sink
    boost::shared_ptr< file_sink > sink0(new file_sink(
        keywords::file_name = "first_date_with_404.log",
        keywords::rotation_size = 16384
    ));

    // Create a text file sink
    boost::shared_ptr< file_sink > sink1(new file_sink(
        keywords::file_name = "first_date_with_200.log",
        keywords::rotation_size = 16384
    ));

    // Create a text file sink
    boost::shared_ptr< file_sink > sink2(new file_sink(
        keywords::file_name = "dates_with_zero_size_after_first_date_with_200.log",
        keywords::rotation_size = 16384
    ));

    // Create a text file sink
    boost::shared_ptr< file_sink > sink3(new file_sink(
        keywords::file_name = "dates_of_saturday_and_sunday_after_first_date_with_200.log",
        keywords::rotation_size = 16384
    ));

    // Create a text file sink
    boost::shared_ptr< file_sink > sink4(new file_sink(
        keywords::file_name = "dates_not_saturday_or_sunday_after_first_date_with_200_having_zero_size.log",
        keywords::rotation_size = 16384
    ));

    // Create a text file sink
    boost::shared_ptr< file_sink > sink5(new file_sink(
        keywords::file_name = "dates_not_saturday_or_sunday_after_first_date_with_200_having_400.log",
        keywords::rotation_size = 16384
    ));

    // Create a text file sink
    boost::shared_ptr< file_sink > sink6(new file_sink(
        keywords::file_name = "last_date_recieved_and_written_to_file.log",
        keywords::rotation_size = 16384
    ));
    /*
    // Create a text file sink
    boost::shared_ptr< file_sink > sink(new file_sink(
        keywords::file_name = "%Y%m%d_%H%M%S_%5N.xml",
        keywords::rotation_size = 16384
    ));
    */
    sink0->set_filter(expr::attr< std::string >("Channel") == "0");
    sink1->set_filter(expr::attr< std::string >("Channel") == "1");
    sink2->set_filter(expr::attr< std::string >("Channel") == "2");
    sink3->set_filter(expr::attr< std::string >("Channel") == "3");
    sink4->set_filter(expr::attr< std::string >("Channel") == "4");
    sink5->set_filter(expr::attr< std::string >("Channel") == "5");
    sink6->set_filter(expr::attr< std::string >("Channel") == "6");



    // Set up where the rotated files will be stored
    init_file_collecting(sink0);
    init_file_collecting(sink1);
    init_file_collecting(sink2);
    init_file_collecting(sink3);
    init_file_collecting(sink4);
    init_file_collecting(sink5);
    init_file_collecting(sink6);

    // Upon restart, scan the directory for files matching the file_name pattern
    sink0->locked_backend()->scan_for_files();
    sink1->locked_backend()->scan_for_files();
    sink2->locked_backend()->scan_for_files();
    sink3->locked_backend()->scan_for_files();
    sink4->locked_backend()->scan_for_files();
    sink5->locked_backend()->scan_for_files();
    sink6->locked_backend()->scan_for_files();

    sink0->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );

    sink1->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );
    sink2->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );
    sink3->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );
    sink4->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );
    sink5->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );
    sink6->set_formatter
    (
        expr::format("record id=\"%1%\" [\"%2%\"] thread_id= %3% %4%")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::attr< attrs::current_thread_id::value_type >("ThreadID")
        % expr::message
    );

    /*
    // Set header and footer writing functors
    namespace bll = boost::lambda;

    sink->locked_backend()->set_open_handler
    (
        bll::_1 << "<?xml version=\"1.0\"?>\n<log>\n"
    );
    sink->locked_backend()->set_close_handler
    (
        bll::_1 << "</log>\n"
    );
    */

    // Add the sink to the core
    //logging::core::get()->add_sink(sink);
    core->add_sink(sink0);
    core->add_sink(sink1);
    core->add_sink(sink2);
    core->add_sink(sink3);
    core->add_sink(sink4);
    core->add_sink(sink5);
    core->add_sink(sink6);
}
//]

//enum { LOG_RECORDS_TO_WRITE = 2000 };
/*
int main(int argc, char* argv[])
{
    try
    {
        // Initialize logging library
        init_logging();


        // And also add some attributes
        logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock());
        logging::core::get()->add_global_attribute("RecordID", attrs::counter< unsigned int >());

        // Do some logging
        src::logger lg;
        for (unsigned int i = 0; i < LOG_RECORDS_TO_WRITE; ++i)
        {
            BOOST_LOG(lg) << "XML log record " << i;
        }

        // Test that XML character decoration works
        BOOST_LOG(lg) << "Special XML characters: &, <, >, \", '";

        return 0;
    }
    catch (std::exception& e)
    {
        std::cout << "FAILURE: " << e.what() << std::endl;
        return 1;
    }
}
*/

/*
*          Copyright Andrey Semashev 2007 - 2015.
* Distributed under the Boost Software License, Version 1.0.
*    (See accompanying file LICENSE_1_0.txt or copy at
*          http://www.boost.org/LICENSE_1_0.txt)
*/
/*
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
#if 0

//[ example_tutorial_file_simple
void init()
{
    logging::add_file_log("sample.log");

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}
//]

// We need this due to this bug: https://svn.boost.org/trac/boost/ticket/4416
//[ example_tutorial_file_advanced_no_callouts
void init()
{
    logging::add_file_log
    (
        keywords::file_name = "sample_%N.log",
        keywords::rotation_size = 10 * 1024 * 1024,
        keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
        keywords::format = "[%TimeStamp%]: %Message%"
    );

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}
//]

#else

//[ example_tutorial_file_advanced
void init()
{
    logging::add_file_log
    (
        keywords::file_name = "sample_%N.log",                                        //*< file name pattern >
        keywords::rotation_size = 10 * 1024 * 1024,                                   //*< rotate files every 10 MiB... >
        keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), //*< ...or at midnight >
        keywords::format = "[%TimeStamp%]: %Message%"                                 //*< log record format >
    );

    logging::core::get()->set_filter
    (
        logging::trivial::severity >= logging::trivial::info
    );
}
//]

#endif
void init_logging()
{
    // Create a text file sink
    boost::shared_ptr< file_sink > sink(new file_sink(
        keywords::file_name = "%Y%m%d_%H%M%S_%5N.xml",
        keywords::rotation_size = 16384
    ));

    // Set up where the rotated files will be stored
    init_file_collecting(sink);

    // Upon restart, scan the directory for files matching the file_name pattern
    sink->locked_backend()->scan_for_files();

    sink->set_formatter
    (
        expr::format("\t<record id=\"%1%\" timestamp=\"%2%\">%3%</record>")
        % expr::attr< unsigned int >("RecordID")
        % expr::attr< boost::posix_time::ptime >("TimeStamp")
        % expr::xml_decor[expr::stream << expr::smessage]
    );

    // Set header and footer writing functors
    namespace bll = boost::lambda;

    sink->locked_backend()->set_open_handler
    (
        bll::_1 << "<?xml version=\"1.0\"?>\n<log>\n"
    );
    sink->locked_backend()->set_close_handler
    (
        bll::_1 << "</log>\n"
    );

    // Add the sink to the core
    logging::core::get()->add_sink(sink);
}
*/

程序选项_1.h

#pragma once
//#include "stdafx.h"    
#include "boost/date_time/posix_time/posix_time.hpp"
#include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
#include <boost/program_options.hpp>
#include <boost/any.hpp>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include "utils.h"

namespace po = boost::program_options;
using namespace std;
using namespace boost::posix_time;
using namespace boost::gregorian;

po::variables_map init_program_options(int argc, char* argv[])
{
    const string  VERSION = "0.2.1";
    try {
        date_duration single_day(1);
        auto facet = new date_input_facet();
        facet->set_iso_extended_format();
        //facet->format("%Y-%m-%d");
        std::locale::global(std::locale(std::locale(), facet));

        std::vector<symbols_enum> symbols_default = { symbols_enum::GBPJPY};

        string prog = "DUKA";

        po::options_description desc(prog + " Allowed options");
        desc.add_options()
            ("help", "produce help message")
            ("version,v", "outputs Version of program")
            ("day,d", po::value<date>()->default_value(day_clock::universal_day()), "specific day format YYYY-MM-DD (default today)")
            ("startdate,s", po::value<date>()->default_value(day_clock::universal_day() - single_day), "start date format YYYY-MM-DD (default today)")
            ("enddate,e", po::value<date>()->default_value(day_clock::universal_day()), "end date format YYYY-MM-DD (default today)")
            ("thread,t", po::value<int>()->default_value(20), "number of threads (default 20)")
            ("folder,f", po::value<string>()->default_value("."), "destination folder (default .)")
            ("candle,c", po::value<timeframe_enum>()->default_value(timeframe_enum::TICK, "TICK"), "use candles instead of ticks. Accepted values TICK M1 M2 M5 M10 M15 M30 H1 H4")
            ("header", po::value<bool>()->default_value(false), "include CSV header (default false)")
            ("symbols", po::value<std::vector<symbols_enum>>()->multitoken()->composing()->default_value(symbols_default, "GBPJPY"), "symbol list using format EURUSD EURGBP")
            ;
        po::positional_options_description pd;
        pd.add("symbols", -1);

        command_line_parser parser{ argc, argv };
        parser.options(desc).positional(pd);
        parsed_options parsed_options = parser.run();

        po::variables_map vm;
        po::store(parsed_options, vm);
        po::notify(vm);

        if (vm.count("help")) {
            cout << desc << "\n";
            exit(0);
        }

        if (vm.count("version")) {
            cout << VERSION << "\n";
            exit(0);
        }

        if (vm.count("day")) {
            cout << "day set to "
                << vm["day"].as<date>() << ".\n";

        }
        else {
            cout << "day was not set.\n";
        }

        if (vm.count("startdate")) {
            cout << "startdate set to "
                << vm["startdate"].as<date>() << ".\n";

        }
        else {
            cout << "startdate was not set.\n";
        }

        if (vm.count("enddate")) {
            cout << "enddate set to "
                << vm["enddate"].as<date>() << ".\n";

        }
        else {
            cout << "enddate was not set.\n";
        }

        if (vm.count("thread")) {
            cout << "thread set to "
                << vm["thread"].as<int>() << ".\n";

        }
        else {
            cout << "thread was not set.\n";
        }

        if (vm.count("folder")) {
            cout << "folder set to "
                << vm["folder"].as<string>() << ".\n";

        }
        else {
            cout << "folder was not set.\n";
        }

        if (vm.count("candle")) {
            cout << "candle set to "
                << vm["candle"].as<timeframe_enum>() << ".\n";

        }
        else {
            cout << "candle level was not set.\n";
        }



        if (vm.count("header")) {
            cout << "header set to "
                << vm["header"].as<bool>() << ".\n";

        }
        else {
            cout << "header was not set.\n";
        }

        if (vm.count("symbols")) {
            cout << "symbols set to "
                << vm["symbols"].as<std::vector<symbols_enum>>() << ".\n";

        }
        else {
            cout << "symbols was not set.\n";
        }
        return vm;
    }
    catch (exception& e) {
        cerr << "error: " << e.what() << "\n";
        exit(1);
    }
    catch (...) {
        cerr << "Exception of unknown type!\n";
    }    
}

最佳答案

why the core and sinks do persist after return and can be used by logmacros defined in c++2.cpp but the loggers dont persist?

Logging 核心是由 Boost.Log 在内部创建和维护的单例。当您第一次调用 logging::core::get() 时,库会创建核心对象并返回指向它的指针。后续调用返回指向同一对象的指针。在应用程序终止之前,单例不会被销毁。全局和特定于线程的属性由核心管理。

接收器在核心中注册,因此它们也一直存在,直到应用程序终止或从核心中删除。

记录器不连接到核心,它们是您的应用程序根据需要创建的独立对象。日志记录器使用日志记录核心来生成日志记录。

记录宏不直接使用核心或接收器。所有日志记录都通过记录器发出,记录器提供特定于源的属性。

您可以从 docs 了解更多关于 Boost.Log 如何运作的信息.

关于c++ - boost.log 含义和作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45259145/

相关文章:

c++ - 使用 constexpr 方法在结构内部进行模板参数化

c++ - Lua:加载第二个字符串后无法获取字段;

c++ - 在吃 EOF 后重用 std::cin

macos - 如何在 Mac 上启动 Syslogd 服务器以接受远程日志消息?

java - 在Springboot中创建2个日志文件

c# - 避免在 native 到托管回调上分配字符串

java - 明确设置 apache HttpClient 日志级别

代码编辑期间 Qt Creator 100% CPU

C++ 使用带有 boost::lexical_cast 的类

c++ - 迭代两个 vector 迭代器比 boost_foreach 更快