1
我使用Boost 1.63 VS2015升壓日誌過濾器在Windows 10如何配置在配置文件中
的代碼如下Boost example。
這是代碼,看起來'severityLogger.open_record'生成的記錄無效,它不會進入if語句中。
logging::core::get()->set_filter(
logging::trivial::severity >= logging::trivial::info);
這是我的配置文件:
#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));
}
但是,如果我添加了這段代碼,它工作正常
[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
謝謝@Andrey,解決問題。 – user1633272