首页 > 其他 > 详细

libbase module

时间:2021-06-13 00:57:07      阅读:29      评论:0      收藏:0      [点我收藏+]

概述

源码解析

1. logging模块

1.1 LOG(INFO) << "print log";

// 如果LOGGING_PREAMBLE(severity)为true,才会将log打印出来
#define LOG(severity) LOGGING_PREAMBLE(severity) && LOG_STREAM(severity)

#define LOGGING_PREAMBLE(severity)      (WOULD_LOG(severity) &&   // unlikely返回0            // severity为fatal则执行abort,默认返回true
   ABORT_AFTER_LOG_EXPR_IF((SEVERITY_LAMBDA(severity)) == ::android::base::FATAL, true) &&        // 保存errno,默认返回true
   ::android::base::ErrnoRestorer())

#define WOULD_LOG(severity)      // ShouldLog很可能返回0,大部分的log其实都不显示出来,所以这里用了UNLIKELY
       // first_stage_init阶段的时候,>= INFO的就返回true
  (UNLIKELY(::android::base::ShouldLog(SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL)) || \ 
   // 默认是false或者等于FATAL
   MUST_LOG_MESSAGE(severity))
#define UNLIKELY( exp )     (__builtin_expect( (exp) != 0, false ))


// 将log打印出来
#define LOG_STREAM(severity)            ::android::base::LogMessage(__FILE__, __LINE__, SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL,                               -1)                .stream()

1.2 ShouldLog-根据log的优先级判断是否应该将log打印出来

bool ShouldLog(LogSeverity severity, const char* tag) {
  static auto& liblog_functions = GetLibLogFunctions();
  // Even though we‘re not using the R liblog functions in this function, if we‘re running on Q,
  // we need to fall back to using gMinimumLogSeverity, since __android_log_is_loggable() will not
  // take into consideration the value from SetMinimumLogSeverity().
  if (liblog_functions) {
    int32_t priority = LogSeverityToPriority(severity);
      // 所以verbose和debug的log可能不会被打印出来
    return __android_log_is_loggable(priority, tag, ANDROID_LOG_INFO);
  } else {
    return severity >= gMinimumLogSeverity;
  }
}

问题

补充

参考

libbase module

原文:https://www.cnblogs.com/pyjetson/p/14879074.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!