提升记录器最大收集器大小

时间:2016-12-13 07:10:16

标签: c++ logging boost

我正在使用BOOST作为我的Logger API。我有一个场景,当达到收集器的最大大小时,它应该停止记录。但目前应用程序正在崩溃。

示例:收集器的最大大小= 10MB,最大文件大小= 4MB,因此它生成两个文件,每个大小为4MB,1个为2MB,应用程序应该停止,但它会在此处崩溃。

代码如下:

sink = boost::make_shared<file_sink>(keywords::file_name = file_name,
    keywords::rotation_size = m_maxLogFileSize,
    keywords::open_mode = std::ios_base::out | std::ios_base::app,
    keywords::auto_flush = true
    );

try{
    sink->locked_backend()->set_file_collector(sinks::file::make_collector(keywords::target = m_dirLocation, keywords::max_size = 1 * 1024));// m_maxLogFileSize));
    //sink->locked_backend()->set_file_collector(sinks::file::make_collector(keywords::target = m_dirLocation, keywords::max_size = 10 * 1024 *1024, keywords::min_free_space = 1024));
}
catch (exception e)
{
    std::cout << "Maximum size reached in collector" << std::endl;
}

sink->set_formatter(
                        expr::stream
                        << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", m_timeFormat) << m_logSeparator
                        << "[" << expr::attr< boost::log::trivial::severity_level >("Severity") << "]" << m_logSeparator << "  "
                        << expr::attr< boost::thread::id >("ThreadID") << m_logSeparator << "  "
                        << expr::attr<std::string>("FileName") << ""
                        << ":" << expr::attr<int>("Line") << m_logSeparator << "  "
                        << expr::attr<std::string>("Function") << m_logSeparator << "  "
                        << expr::xml_decor[expr::stream << expr::smessage]
                    );

sink->locked_backend()->scan_for_files();
sink->locked_backend()->auto_flush(true);

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

0 个答案:

没有答案