我正在使用boost_log 1.69记录到文件(每个用户项目都有单独的日志)。我通过调用以下方法在运行时更改活动日志文件:
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks.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>
#include <boost/log/support/date_time.hpp>
#include <boost/log/core.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/exception_handler.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;
src::severity_logger<logging::trivial::severity_level> lg = src::severity_logger<logging::trivial::severity_level>();
boost::shared_ptr< sinks::synchronous_sink< sinks::text_file_backend > > g_file_sink = nullptr;
void CLogger::InitLogFile(string filePath)
{
if (g_file_sink != nullptr)
{
logging::core::get()->remove_sink(g_file_sink);
g_file_sink.reset();
}
g_file_sink = logging::add_file_log
(
keywords::file_name = filePath + ".log",
keywords::open_mode = std::ios_base::app //to append to existing file if found
);
logging::formatter formatter =
expr::stream
<< expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << " *"
<< expr::attr< logging::trivial::severity_level >("Severity") << "* "
<< expr::message;
g_file_sink->set_formatter(formatter);
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
logging::add_common_attributes();
// Set header and footer writing functors
//g_file_sink->locked_backend()->set_open_handler(&write_header);
//g_file_sink->locked_backend()->set_close_handler(&write_footer);
//init_exception_handler();
}
在程序的某些位置,我想更改硬盘中活动日志文件的位置或获取其内容并将其复制到新的日志文件中。 我缺少某种对应的“ rename_file_log”吗?