提升记录器刷新到文件
Boost logger flush to file
我需要在执行每个日志记录代码行后进行提升以记录。是否可以以某种方式将接收器配置为以这种方式运行?当前日志在程序结束后立即填充。
#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>
#include <conio.h>;
namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
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
);
logging::core::get();
}
//]
#endif
int main(int, char*[])
{
init();
logging::add_common_attributes();
using namespace logging::trivial;
src::severity_logger< severity_level > lg;
BOOST_LOG_SEV(lg, trace) << "A trace severity message";
BOOST_LOG_SEV(lg, debug) << "A debug severity message";
BOOST_LOG_SEV(lg, info) << "An informational severity message";
BOOST_LOG_SEV(lg, warning) << "A warning severity message";
BOOST_LOG_SEV(lg, error) << "An error severity message";
BOOST_LOG_SEV(lg, fatal) << "A fatal severity message";
std::cin.get();
return 0;
}
正如评论者所说,只需添加auto_flush
关键字:
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::auto_flush = true,
keywords::format = "[%TimeStamp%]: %Message%" /* log record format */
);
住在科里鲁
相关文章:
- 如何在 Windows 中立即刷新文件夹图标
- 如何使用 Boost 的"mapped_file_sink"类刷新内存映射文件?
- 如何用刷新内容替换现有文件到资产文件夹中
- 刷新属性在简单文件通道中的工作原理
- 如何确保数据刷新到文件 IO (WriteFile()) 上的 HDD(未缓冲)
- 由触发器调用的 MS SQL XP 更改 C++ 文件日期戳,以允许刷新表单应用程序 vb.net
- 在监视器超时之前将文件刷新到磁盘
- 刷新不调用文件更改
- 如何为刷新ROM创建C++可执行文件
- 提升记录器刷新到文件
- 获取文件数据后刷新 cout 的问题
- 如何在使用FFmpeg写入mp4文件时将缓冲区数据刷新到磁盘
- 使用c++的流将文件写入或刷新到异步NFS
- QFileSystemWatcher:检测文件是否已刷新
- 可能在刷新操作中写入文件失败
- 具有桌面.ini和即时刷新功能的自定义文件夹图标
- 如何在win32上刷新stdlib输出文件?
- 头文件刷新/更新
- 头文件未刷新- Visual c++ 2012
- 如何强制文件刷新