日志记录
摘要
枚举 |
|
---|---|
android_LogPriority{
|
枚举 Android 日志优先级值,按优先级升序排列。 |
log_id{
|
枚举 标识用于 __android_log_buf_write() 和 __android_log_buf_print() 的特定日志缓冲区。 |
类型定义 |
|
---|---|
__android_aborter_function)(const char *abort_message)
|
typedefvoid(*
当 liblog 因 __android_log_assert() 失败而中止时调用的 'abort' 函数的原型。 |
__android_logger_function)(const struct __android_log_message *log_message)
|
typedefvoid(*
为每个日志消息调用的 'logger' 函数的原型。 |
android_LogPriority
|
typedef Android 日志优先级值,按优先级升序排列。 |
log_id_t
|
typedef枚举 log_id
标识用于 __android_log_buf_write() 和 __android_log_buf_print() 的特定日志缓冲区。 |
函数 |
|
---|---|
__android_log_assert(const char *cond, const char *tag, const char *fmt, ...)
|
void
将断言失败写入日志(作为
ANDROID_LOG_FATAL )和 stderr,然后调用 abort(3)。 |
__android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
|
int
将格式化字符串写入日志缓冲区
id ,优先级为 prio ,标签为 tag 。 |
__android_log_buf_write(int bufID, int prio, const char *tag, const char *text)
|
int
将常量字符串
text 写入日志缓冲区 id ,优先级为 prio ,标签为 tag 。 |
__android_log_call_aborter(const char *abort_message)
|
void
调用存储的中止函数。
|
__android_log_default_aborter(const char *abort_message)
|
void
在设备上设置 android_set_abort_message(),然后调用 aborts()。
|
__android_log_get_minimum_priority(void)
|
int32_t
获取此进程将记录的最低优先级。
|
__android_log_id_is_valid(log_id_t id)
|
bool
|
__android_log_is_loggable(int prio, const char *tag, int default_prio)
|
int
使用每标签属性“log.tag。
|
__android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio)
|
int
使用每标签属性“log.tag。
|
__android_log_logd_logger(const struct __android_log_message *log_message)
|
void
将日志消息写入 logd。
|
__android_log_print(int prio, const char *tag, const char *fmt, ...)
|
int
将格式化字符串写入日志,优先级为
prio ,标签为 tag 。 |
__android_log_set_aborter(__android_aborter_function aborter)
|
void
设置用户定义的中止函数,该函数在 __android_log_assert() 失败时调用。
|
__android_log_set_default_tag(const char *tag)
|
void
如果在写入日志消息时未提供标签,则设置默认标签。
|
__android_log_set_logger(__android_logger_function logger)
|
void
设置用户定义的日志记录器函数。
|
__android_log_set_minimum_priority(int32_t priority)
|
int32_t
设置此进程将记录的最低优先级。
|
__android_log_stderr_logger(const struct __android_log_message *log_message)
|
void
将日志消息写入 stderr。
|
__android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
|
int
等同于 __android_log_print(),但接受
va_list 。 |
__android_log_write(int prio, const char *tag, const char *text)
|
int
将常量字符串
text 写入日志,优先级为 prio ,标签为 tag 。 |
__android_log_write_log_message(struct __android_log_message *log_message)
|
void
写入 log_message 指定的日志消息。
|
结构体 |
|
---|---|
__android_log_message |
用于通过 __android_log_write_logger_data() 将日志消息写入 liblog,并将日志消息发送到 __android_log_set_logger() 中指定的用户定义日志记录器的数据结构。 |
枚举
android_LogPriority
在android/log.h
中声明
android_LogPriority
Android 日志优先级值,按优先级升序排列。
属性 | |
---|---|
ANDROID_LOG_DEBUG |
调试日志记录。 通常应在发布 APK 中停用。 |
ANDROID_LOG_DEFAULT |
默认优先级,仅供内部使用。 |
ANDROID_LOG_ERROR |
错误日志记录。 用于不可恢复的故障。 |
ANDROID_LOG_FATAL |
致命日志记录。 中止时使用。 |
ANDROID_LOG_INFO |
信息日志记录。 通常应在发布 APK 中停用。 |
ANDROID_LOG_SILENT |
仅供内部使用。 |
ANDROID_LOG_UNKNOWN |
仅供内部使用。 |
ANDROID_LOG_VERBOSE |
详细日志记录。 通常应在发布 APK 中停用。 |
ANDROID_LOG_WARN |
警告日志记录。 用于可恢复的故障。 |
log_id
在android/log.h
中声明
log_id
标识用于 __android_log_buf_write() 和 __android_log_buf_print() 的特定日志缓冲区。
属性 | |
---|---|
LOG_ID_CRASH |
崩溃日志缓冲区。 |
LOG_ID_DEFAULT |
让日志记录函数选择最佳日志目标。 |
LOG_ID_EVENTS |
事件日志缓冲区。 |
LOG_ID_KERNEL |
内核日志缓冲区。 |
LOG_ID_MAIN |
主日志缓冲区。 这是应用唯一可用的日志缓冲区。 |
LOG_ID_MAX |
|
LOG_ID_MIN |
|
LOG_ID_RADIO |
无线日志缓冲区。 |
LOG_ID_SECURITY |
安全日志缓冲区。 |
LOG_ID_STATS |
统计信息日志缓冲区。 |
LOG_ID_SYSTEM |
系统日志缓冲区。 |
类型定义
__android_aborter_function
在android/log.h
中声明
void(* __android_aborter_function)(const char *abort_message)
当 liblog 因 __android_log_assert() 失败而中止时调用的 'abort' 函数的原型。
__android_logger_function
在android/log.h
中声明
void(* __android_logger_function)(const struct __android_log_message *log_message)
为每个日志消息调用的 'logger' 函数的原型。
android_LogPriority
在android/log.h
中声明
enum android_LogPriority android_LogPriority
Android 日志优先级值,按优先级升序排列。
log_id_t
在android/log.h
中声明
enum log_id log_id_t
标识用于 __android_log_buf_write() 和 __android_log_buf_print() 的特定日志缓冲区。
函数
__android_log_assert
在android/log.h
中声明
void __android_log_assert( const char *cond, const char *tag, const char *fmt, ... )
__android_log_buf_print
在android/log.h
中声明
int __android_log_buf_print( int bufID, int prio, const char *tag, const char *fmt, ... )
将格式化字符串写入日志缓冲区 id
,优先级为 prio
,标签为 tag
。
格式化的详细信息与 printf(3) 相同。
应用应改用 __android_log_print()。
详细信息 | |
---|---|
返回值 |
如果消息已写入日志,则返回 1;如果未写入,则返回 -EPERM;请参阅 __android_log_is_loggable()。
|
__android_log_buf_write
在android/log.h
中声明
int __android_log_buf_write( int bufID, int prio, const char *tag, const char *text )
将常量字符串 text
写入日志缓冲区 id
,优先级为 prio
,标签为 tag
。
应用应改用 __android_log_write()。
详细信息 | |
---|---|
返回值 |
如果消息已写入日志,则返回 1;如果未写入,则返回 -EPERM;请参阅 __android_log_is_loggable()。
|
__android_log_call_aborter
在android/log.h
中声明
void __android_log_call_aborter( const char *abort_message )
调用存储的中止函数。
这允许其他日志记录库通过在 liblog 中调用此函数来使用相同的中止函数。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
__android_log_default_aborter
在android/log.h
中声明
void __android_log_default_aborter( const char *abort_message )
在设备上设置 android_set_abort_message(),然后调用 aborts()。
这是默认的中止程序。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
__android_log_get_minimum_priority
在android/log.h
中声明
int32_t __android_log_get_minimum_priority( void )
获取此进程将记录的最低优先级。
自 API 级别 30 起可用。
详细信息 | |
---|---|
返回值 |
当前最低优先级,如果未设置,则为
ANDROID_LOG_DEFAULT 。 |
__android_log_id_is_valid
在android/log.h
中声明
bool __android_log_id_is_valid( log_id_t id )
__android_log_is_loggable
在android/log.h
中声明
int __android_log_is_loggable( int prio, const char *tag, int default_prio )
使用每标签属性“log.tag。
非零结果表示是,零表示否。
如果同时设置了标签优先级和 __android_log_set_minimum_priority() 设置的最低优先级,则取两个值中的较低者作为记录所需的最低优先级。如果只设置了一个,则使用该值确定所需的最低优先级。如果都没有设置,则使用 default_priority。
自 API 级别 30 起可用。
详细信息 | |||||||
---|---|---|---|---|---|---|---|
参数 |
|
||||||
返回值 |
一个整数,1 表示消息可记录,0 表示不可记录。
|
__android_log_is_loggable_len
在android/log.h
中声明
int __android_log_is_loggable_len( int prio, const char *tag, size_t len, int default_prio )
使用每标签属性“log.tag。
非零结果表示是,零表示否。
如果同时设置了标签优先级和 __android_log_set_minimum_priority() 设置的最低优先级,则取两个值中的较低者作为记录所需的最低优先级。如果只设置了一个,则使用该值确定所需的最低优先级。如果都没有设置,则使用 default_priority。
自 API 级别 30 起可用。
详细信息 | |||||||||
---|---|---|---|---|---|---|---|---|---|
参数 |
|
||||||||
返回值 |
一个整数,1 表示消息可记录,0 表示不可记录。
|
__android_log_logd_logger
在android/log.h
中声明
void __android_log_logd_logger( const struct __android_log_message *log_message )
将日志消息写入 logd。
这是一个 __android_logger_function,可以提供给 __android_log_set_logger()。它是在设备上运行 liblog 时的默认日志记录器。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
__android_log_print
在android/log.h
中声明
int __android_log_print( int prio, const char *tag, const char *fmt, ... )
将格式化字符串写入日志,优先级为 prio
,标签为 tag
。
格式化的详细信息与 printf(3) 相同。
详细信息 | |
---|---|
返回值 |
如果消息已写入日志,则返回 1;如果未写入,则返回 -EPERM;请参阅 __android_log_is_loggable()。
|
__android_log_set_aborter
在android/log.h
中声明
void __android_log_set_aborter( __android_aborter_function aborter )
设置用户定义的中止函数,该函数在 __android_log_assert() 失败时调用。
强烈建议此用户定义的中止函数中止且不返回,但并非严格要求。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
__android_log_set_default_tag
在android/log.h
中声明
void __android_log_set_default_tag( const char *tag )
如果在写入日志消息时未提供标签,则设置默认标签。
默认为 getprogname()。这将把标签截断为最大日志消息大小,尽管合适的标签应该小得多。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
__android_log_set_logger
在android/log.h
中声明
void __android_log_set_logger( __android_logger_function logger )
设置用户定义的日志记录器函数。
发送到 liblog 的所有日志消息都将设置为 logger 指定的函数指针进行处理。不要求日志消息已由换行符终止。如果需要换行符进行行分隔,此函数应添加换行符。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
__android_log_set_minimum_priority
在android/log.h
中声明
int32_t __android_log_set_minimum_priority( int32_t priority )
设置此进程将记录的最低优先级。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
||
返回值 |
先前设置的最低优先级,如果未设置,则为
ANDROID_LOG_DEFAULT 。 |
__android_log_stderr_logger
在android/log.h
中声明
void __android_log_stderr_logger( const struct __android_log_message *log_message )
将日志消息写入 stderr。
这是一个 __android_logger_function,可以提供给 __android_log_set_logger()。它是在主机上运行 liblog 时的默认日志记录器。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|
__android_log_vprint
在android/log.h
中声明
int __android_log_vprint( int prio, const char *tag, const char *fmt, va_list ap )
等同于 __android_log_print(),但接受 va_list
。
(如果 __android_log_print() 像 printf(),这就像 vprintf()。)
详细信息 | |
---|---|
返回值 |
如果消息已写入日志,则返回 1;如果未写入,则返回 -EPERM;请参阅 __android_log_is_loggable()。
|
__android_log_write
在android/log.h
中声明
int __android_log_write( int prio, const char *tag, const char *text )
将常量字符串 text
写入日志,优先级为 prio
,标签为 tag
。
详细信息 | |
---|---|
返回值 |
如果消息已写入日志,则返回 1;如果未写入,则返回 -EPERM;请参阅 __android_log_is_loggable()。
|
__android_log_write_log_message
在android/log.h
中声明
void __android_log_write_log_message( struct __android_log_message *log_message )
写入 log_message 指定的日志消息。
log_message 包含日志记录器可能使用的附加文件名和行号信息。log_message 已版本化以实现向后兼容性。这假定已通过 __android_log_is_loggable() 检查了可记录性。更高级别的日志记录库(例如 libbase)首先检查可记录性,然后格式化其缓冲区,再通过此函数将消息传递给 liblog,因此我们不希望在此处重复进行可记录性检查。
自 API 级别 30 起可用。
详细信息 | |||
---|---|---|---|
参数 |
|