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

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

被折叠的 条评论
为什么被折叠?



