在程序中添加红色部分代码:
或如下代码
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