これだと、nul デバイスに対して出力する処理が入るので、負荷を取り除くという面では、よろしくないコード
ポイントは、
Windows では nul というファイルが /dev/null に相当する
nul というファイルは、どこにでも存在している扱いになるので、追加書き込みモードで開く必要がある点
#include <boost/date_time.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/support/date_time.hpp>
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace keywords = boost::log::keywords;
namespace sinks = boost::log::sinks;
namespace expr = boost::log::expressions;
...
//#define DEBUG_LOG_FILE "c:/logs/%Y_%m_%d.log"
...
boost::log::add_file_log(
#ifdef DEBUG_LOG_FILE
keywords::file_name = DEBUG_LOG_FILE,
#else
keywords::file_name = "nul",
keywords::open_mode = std::ios_base::out | std::ios_base::app,
#endif
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0),
keywords::format =
(
expr::stream
<< expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S")
<< ": <" << logging::trivial::severity
<< "> " << expr::smessage
),
keywords::auto_flush = true
);
BOOST_LOG_TRIVIAL(debug) << "this is a debug output.";
...
0 件のコメント:
コメントを投稿