0
我已經使用boost 1.63實現了一個全局日誌記錄器。這裏是初始化:升壓日誌 - 處理關機場景
BOOST_LOG_GLOBAL_LOGGER_INIT(my_logger, src::severity_logger_mt<severity_level>)
{
typedef sinks::synchronous_sink<sinks::text_file_backend> file_sink;
boost::shared_ptr<file_sink> sink(new file_sink(
keywords::file_name = "/var/log/testApp/%Y%m%d_%H%M%S_testApp.log",
keywords::rotation_size = 5 * 1024 * 1024,
keywords::auto_flush = true));
sink->locked_backend()->set_file_collector(sinks::file::make_collector(
keywords::target = "/var/log/testApp/oldLogs",
keywords::max_size = 5 * 1024 * 1024 * 2,
keywords::min_free_space = 5 * 1024 * 1024 * 2,
keywords::max_files = 2));
sink->locked_backend()->scan_for_files();
sink->set_formatter(
expr::format("[%1%]<%2%> : %3%") %
expr::attr<boost::posix_time::ptime>("TimeStamp") %
expr::attr<severity_level>("Severity") %
expr::smessage);
logging::core::get()->add_sink(sink);
logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock());
src::severity_logger_mt<severity_level> slg;
return slg;
}
當一個程序意外地完成(例如須藤殺-9 PID或斷電)日誌文件沒有移動到oldlogs中的目錄(也當程序再次運行)和/ var/log/testApp目錄可能包含許多日誌文件。
是否可以處理這種情況?