AndroidT(13) Log 系统 -- logger_write 库实现解析(四)

本文深入解析Android LOG系统的工作原理,重点介绍了__android_log_write_log_message的实现过程,包括logtag的确定方式、logger_function的具体作用及write_to_log的处理流程。

1.概览

  经过上及章节的分析可见,不论是那种风格的LOG接口实现,最终调用的都是logger_write库中过提供的一些列接口来处理log内容的。下面就来看看 logger_write 库的实现,本章节会随着后续涉及接口的不断增加而动态更新。

2. __android_log_write_log_message 的实现

__android_log_write_log_message
    //code 1
    if (log_message->tag == nullptr)
        log_message->tag = GetDefaultTag().c_str();
    //code 2
    logger_function(log_message)

2.1 log tag确定 – code 1

  一般使用Android 的LOG系统前,会先定义LOG_TAG宏的。但是如果没定义的话,总不能null吧,所以Android LOG系统贴心的使用程序的简称作为在用户没有设置LOG_TAG场景下的TAG值,对于代码如下

static const char* getprogname() {
   
   
#ifdef _WIN32
    ...
#else
  return program_invocation_short_name;
#endif
}

  我们不关心Win32的场景,所以返回的就是 program_invocation_short_name 了,它的描述见man手册

NAME
       program_invocation_name, program_invocation_short_name - obtain name used to invoke calling program

SYNOPSIS
       #define _GNU_SOURCE         /* See feature_test_macros(7) */
       #include <errno.h>

       extern char *program_invocation_name;
       extern char *program_invocation_short_name;

DESCRIPTION
       program_invocation_name  contains the name that was used to invoke the calling program.  This is the same as the value of argv[0] in main(), with the difference that the scope of program_invocation_name is global.
       program_invocation_short_name contains the basename component of name that was used to invoke the calling program.  That is, it is the same value  as program_invocation_name, with all text up to and including the 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值