使用boost log时,输出的日志文件中TimeStamp为空解决办法

在程序中添加红色部分代码:

或如下代码

boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());

void init() {
    <span style="color:#cc0000;">boost::log::add_common_attributes();</span>
     logging::add_file_log
    (
        keywords::file_name = "sample_%N.log",                                        /*< file name pattern >*/
        keywords::rotation_size = 10 * 1024 * 1024,                                   /*< rotate files every 10 MiB... >*/
        keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), /*< ...or at midnight >*/
        keywords::format = "[%TimeStamp%]: %Message%"                                 /*< log record format >*/
    );


在boost官网中查了下add_common_attributes()函数的作用:

Function add_common_attributes

boost::log::add_common_attributes — Simple attribute initialization routine.

Synopsis

// In header: <boost/log/utility/setup/common_attributes.hpp>

void add_common_attributes();

Description

The function adds commonly used attributes to the logging system. Specifically, the following attributes are registered globally:
  • LineID - logging records counter with value type unsigned int

  • TimeStamp - local time generator with value type boost::posix_time::ptime

  • ProcessID - current process identifier with value type attributes::current_process_id::value_type

  • ThreadID - in multithreaded builds, current thread identifier with value type attributes::current_thread_id::value_type

使用该函数,可使用以上提到的四个属性的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值