我在Windows 10上使用VS2015中的Boost 1.63。
代码正在关注Boost example。
这里的代码似乎是由< severityLogger.open_record'生成的记录。无效,它不会进入if语句。
#include <boost/format.hpp>
#include <boost/locale/generator.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/log/utility/setup/settings_parser.hpp>
#include <boost/phoenix.hpp>
namespace logging = boost::log;
namespace expr = boost::log::expressions;
namespace keywords = boost::log::keywords;
namespace sinks = boost::log::sinks;
namespace src = boost::log::sources;
src::wseverity_logger<logging::trivial::severity_level> severityLogger;
std::wifstream strm(L"config\\logger.ini");
strm.imbue(std::locale(strm.getloc(), new std::codecvt_utf8<wchar_t, 0x10ffff, std::consume_header>));
auto settings = logging::parse_settings(strm);
logging::init_from_settings(settings);
logging::add_common_attributes();
auto rec = severityLogger.open_record(keywords::severity = logging::trivial::severity_level::info);
if (rec) { // Unable to go here !!!
logging::wrecord_ostream strm(rec);
strm << L"Some message";
strm.flush();
severityLogger_.push_record(boost::move(rec));
}
但是,如果我添加这段代码,它可以正常工作:
logging::core::get()->set_filter(
logging::trivial::severity >= logging::trivial::info);
这是我的配置文件:
[Core]
DisableLogging=false
Filter="%Severity% >= info"
[Sinks.File]
Destination=TextFile
FileName="App_%Y-%m-%d.%N.log"
Format="%TimeStamp% %Severity% - %Message%"
AutoFlush=true
TimeBasedRotation="00:00:00"
RotationSize=10485760