相关疑难解决方法(0)

提升日志以打印源代码文件名和行号

我正在使用Boost(1.55.0)登录我的C++应用程序.我已经能够生成这种格式的日志

[2014-Jul-15 10:47:26.137959]: <debug>  A regular message
Run Code Online (Sandbox Code Playgroud)

我希望能够在生成日志的位置添加源文件名和行号.

[2014-Jul-15 10:47:26.137959]: <debug> [filename:line_no] A regular message
Run Code Online (Sandbox Code Playgroud)

例:

[2014-Jul-15 10:47:26.137959]: <debug> [helloworld.cpp : 12] A regular message
Run Code Online (Sandbox Code Playgroud)

源代码:

#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 <boost/log/expressions.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/attributes/attribute.hpp>
#include <boost/log/attributes/attribute_cast.hpp>
#include <boost/log/attributes/attribute_value.hpp>
#include <boost/make_shared.hpp>
#include <boost/property_tree/ptree.hpp>

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", …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-logging boost-log

14
推荐指数
3
解决办法
8094
查看次数

标签 统计

boost ×1

boost-log ×1

boost-logging ×1

c++ ×1