boost log库_Boost.log库使用方法

做服务器开发首要做的事情,就是将日志系统建立起来。这个系统也是方便我们检查服务器的问题。

初始化日志系统

这是一个初始化日志系统的代码。我这里是使用了一个配置文件来做boost.log的设置的。所以代码写起来是非常的简洁。

#include

#include

#include

#include

#include

#include

#include

bool init_log_environment(std::string _cfg)

{

namespace logging = boost::log;

using namespace logging::trivial;

if (!boost::filesystem::exists("./log/"))

{

boost::filesystem::create_directory("./log/");

}

logging::add_common_attributes();

logging::register_simple_formatter_factory("Severity");

logging::register_simple_filter_factory("Severity");

std::ifstream file(_cfg);

try

{

logging::init_from_stream(file);

}

catch (const std::exception& e)

{

std::cout << "init_logger is fail, read log config file fail. curse: " << e.what() << std::endl;

exit(-2);

}

return true;

}

其实最核心的代码就是logging::init_from_stream这个函数。他能加载你对日志的配置信息。这样比起一般将sink设置,日志级别设置写到代码里面的方式要更加简单。接下来我们来看看配置文件的写法。

配置日志

[Core]

DisableLogging=false

Filter="%Severity% >= trace"

[Sinks.console]

Filter="%Severity% > trace "

Destination=Console

Format="[%TimeStamp%] [%Sever

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码解释:void CopleyAmplifier::SetNewPVTMotionStartTime(boost::posix_time::ptime time,CouchTrjType pvt_point) { //Record the time stamp and data. m_bool_pvt_started = true; m_start_motion_time_us = PosixTime2Integer<unsigned long long>(time); m_last_pvt_data.p = m_start_pos; //Send the last dummy data calculated by the motion start time. ptime current_time = microsec_clock::universal_time(); ptime couch_time = Integer2PosixTime<unsigned long long>(pvt_point.t, current_time); ptime couch_to_L1_time = Integer2PosixTime<unsigned long long>(pvt_point.timeReachToBuffer, current_time); unsigned char next_point_time = round((pvt_point.t-m_start_motion_time_us)/1000.0)-m_total_motion_time_ms; if(next_point_time<4) { GcLogInfo(m_log_id, __FUNCTION__, "<CopleyStartPVT>Motion start time:%s. First couch time:%s.First couch to L1 time:%s.", boost::posix_time::to_simple_string(time).c_str(), boost::posix_time::to_simple_string(couch_time).c_str(), boost::posix_time::to_simple_string(couch_to_L1_time).c_str()); GcLogInfo(m_log_id, __FUNCTION__, "next_point_time: %d.",next_point_time); BOOST_THROW_EXCEPTION(AxisException() <<Axis_Error_Msg("Start PVT time failed! No enough time for First PVT data!")); } AmpPVTData dummy_data = {next_point_time,0,0}; //Send the left dummy data. dummy_data.time = next_point_time; Gantry::Array seg_cmd = ComposePVTRawData(dummy_data,m_next_pvt_index,1); GcLogDebugExpect(m_need_trace, m_log_id, __FUNCTION__, "<CopleyStartPVT>The %dth PVT dummy data.", m_next_pvt_index); WriteSDO(Gantry::ODAddress(COPLEY_PVT_DATA, 0), (unsigned long long)seg_cmd.GetValue<unsigned long long>()); GcLogInfo(m_log_id, __FUNCTION__, "<CopleyStartPVT>Motion start time:%s. First couch time:%s.First couch to L1 time:%s.", boost::posix_time::to_simple_string(time).c_str(), boost::posix_time::to_simple_string(couch_time).c_str(), boost::posix_time::to_simple_string(couch_to_L1_time).c_str()); m_total_motion_time_ms += dummy_data.time; m_lasttrj_segments.push_back(seg_cmd.GetValue<unsigned long long>()); ++m_next_pvt_index; GcLogInfo(m_log_id, __FUNCTION__, "<CopleyStartPVT>Motion Started. Start position %f mm.", pvt_point.p); }
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值