【飞鸟圣源码】【交友免费源码】【durid源码解析】easyloggingpp 源码

2024-11-24 21:41:53 来源:bootstrap net源码 分类:百科

1.easylogging源码学习笔记(6)

easyloggingpp 源码

easylogging源码学习笔记(6)

       `LOG` 是默认日志、CLOG自定义日志、LOG_IF条件日志

       特殊日志

       LOG_EVERY_N、LOG_AFTER_N、飞鸟圣源码LOG_N_TIMES

       for (int i = 1; i <= ; ++i) {

       LOG_EVERY_N(2, INFO) << "Logged every second iter";

       }// 5 logs written; 2, 4, 6, 7,

       for (int i = 1; i <= ; ++i) {

       LOG_AFTER_N(2, INFO) << "Log after 2 hits; " << i;

       }// 8 logs written; 3, 4, 5, 6, 7, 8, 9,

       for (int i = 1; i <= ; ++i) {

       LOG_N_TIMES(3, INFO) << "Log only 3 times; " << i;

       }// 3 logs writter; 1, 2, 3

       条件日志和特殊日志可以搭配使用

       * `VLOG_IF(condition, verbose-level)`

       * `CVLOG_IF(condition, verbose-level, loggerID)`

       * `VLOG_EVERY_N(n, verbose-level)`

       * `CVLOG_EVERY_N(n, verbose-level, loggerID)`

       * `VLOG_AFTER_N(n, verbose-level)`

       * `CVLOG_AFTER_N(n, verbose-level, loggerID)`

       * `VLOG_N_TIMES(n, verbose-level)`

       * `CVLOG_N_TIMES(n, verbose-level, loggerID)`

       日志详细等级判定

       if (VLOG_IS_ON(2)) {

       // Verbosity level 2 is on for this file

       }

       性能追踪

       * `TIMED_FUNC(obj-name)`

       * `TIMED_SCOPE(obj-name, block-name)`

       * `TIMED_BLOCK(obj-name, block-name)`

       这些宏实际上都是关于el::base::type::PerformanceTrackerPtr,一个指向el::base::PerformanceTracker的交友免费源码指针

       #if defined(ELPP_FEATURE_ALL) || defined(ELPP_FEATURE_PERFORMANCE_TRACKING)

       PerformanceTracker::PerformanceTracker(const std::string& blockName,

       base::TimestampUnit timestampUnit,

       const std::string& loggerId,

       bool scopedLog, Level level) :

       m_blockName(blockName), m_timestampUnit(timestampUnit), m_loggerId(loggerId), m_scopedLog(scopedLog),

       m_level(level), m_hasChecked(false), m_lastCheckpointId(std::string()), m_enabled(false) {

       #if !defined(ELPP_DISABLE_PERFORMANCE_TRACKING) && ELPP_LOGGING_ENABLED

       // We store it locally so that if user happen to change configuration by the end of scope

       // or before calling checkpoint, we still depend on state of configuration at time of construction

       el::Logger* loggerPtr = ELPP->registeredLoggers()->get(loggerId, false);

       m_enabled = loggerPtr != nullptr && loggerPtr->m_typedConfigurations->performanceTracking(m_level);

       if (m_enabled) {

       base::utils::DateTime::gettimeofday(&m_startTime);

       }

       #endif // !defined(ELPP_DISABLE_PERFORMANCE_TRACKING) && ELPP_LOGGING_ENABLED

       }

       在构造函数中获取一个时间,

       PerformanceTracker::~PerformanceTracker(void) {

       #if !defined(ELPP_DISABLE_PERFORMANCE_TRACKING) && ELPP_LOGGING_ENABLED

       if (m_enabled) {

       base::threading::ScopedLock scopedLock(lock());

       if (m_scopedLog) {

       base::utils::DateTime::gettimeofday(&m_endTime);

       base::type::string_t formattedTime = getFormattedTimeTaken();

       PerformanceTrackingData data(PerformanceTrackingData::DataType::Complete);

       data.init(this);

       data.m_formattedTimeTaken = formattedTime;

       PerformanceTrackingCallback* callback = nullptr;

       for (const std::pair& h

       : ELPP->m_performanceTrackingCallbacks) {

       callback = h.second.get();

       if (callback != nullptr && callback->enabled()) {

       callback->handle(&data);

       }

       }

       }

       }

       #endif // !defined(ELPP_DISABLE_PERFORMANCE_TRACKING)

       }

       在析构函数中获取一个时间,处理时间data,使用PerformanceTrackingCallback类型指针callback,并在callback->handle(&data)中处理输出。

       由于定义了ELPP_FEATURE_PERFORMANCE_TRACKING,因此在初始化(INITIALIZE_EASYLOGGINGPP)中实际上是安装了一个base::DefaultPerformanceTrackingCallback。

       在PerformanceTracker类的durid源码解析handle函数中,callback是一个PerformanceTrackingCallback类型指针,由于安装的是DefaultPerformanceTrackingCallback对象,因此是innodb锁源码一个基类指针指向了派生类对象。处理输出的逻辑在DefaultPerformanceTrackingCallback类的handle函数中。

       DefaultPerformanceTrackingCallback类的handle函数首先会将数据成员m_data的指针赋值给函数参数,并创建一个base::type::stringstream_t类型的pixhawk源码框架对象ss用于构建输出内容。根据m_data的dataType,输出不同的信息。在输出时,会使用el::base::Writer类构造并输出内容。

本文地址:http://5o.net.cn/news/76b258597338.html 欢迎转发