相关疑难解决方法(0)

提升日志severity_logger init_from_stream

我正在使用boost 1.54.0.您可以在下面找到说明我的问题的最小示例.

我使用boost日志的severity_logger.我想从流中配置我的接收器.(在下面的示例中,我使用了一个字符串流.在我的实际应用程序中,流来自一个文件.)我想使用%Severity%来输出或过滤.

我的问题是:如果我在下面的例子中给出它,%Severity%为空.

%LineID%和%Message%按预期填充.如果我在outcommented行中设置了一个接收器,它会按预期工作.

有任何想法吗?

#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/from_stream.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/expressions.hpp>

enum SeverityLevel { trace, fatal };

int main (int argc, char *argv[])
{
    boost::log::add_common_attributes();
    /*
    struct severity_tag;
    boost::log::add_console_log(std::clog,
        boost::log::keywords::format = (
            boost::log::expressions::stream
                << boost::log::expressions::attr< unsigned int >("LineID")
                << ": <" << boost::log::expressions::attr<SeverityLevel, severity_tag >("Severity")
                << "> " << boost::log::expressions::smessage)
    ); */

    std::stringstream s;
    s << "[Sinks.MySink]" << std::endl;
    s << "Destination=Console" << std::endl;
    s << "Format=\"%LineID%: <%Severity%> - %Message%\"" …
Run Code Online (Sandbox Code Playgroud)

c++ logging boost boost-log

11
推荐指数
1
解决办法
3310
查看次数

没有创建日志文件

我在以下链接中使用该示例.

https://www.boost.org/doc/libs/1_57_0/libs/log/doc/html/log/detailed/utilities.html#log.detailed.utilities.setup.settings_file

我的代码如下.

#include "stdafx.h"
#include <iostream>
#include <fstream>

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/from_stream.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/regex.hpp>

namespace logging = boost::log;
namespace keywords = boost::log::keywords;
#define BOOST_LOG_DYN_LINK 1


int main(int, char*[])
{
    //init_logging();
    std::ifstream file("settings.ini");
    logging::init_from_stream(file);

    BOOST_LOG_TRIVIAL(trace) << "This is a trace severity message";
    BOOST_LOG_TRIVIAL(debug) << "This is a debug severity message";
    BOOST_LOG_TRIVIAL(info) << "This is an informational severity message";
    BOOST_LOG_TRIVIAL(warning) << "This is a warning severity message";
    BOOST_LOG_TRIVIAL(error) << …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-logging boost-log

0
推荐指数
1
解决办法
110
查看次数

标签 统计

boost ×2

boost-log ×2

c++ ×2

boost-logging ×1

logging ×1