Logging

#include <log.h>

Summary

Enumerations

android_LogPriority{
  ANDROID_LOG_UNKNOWN = 0,
  ANDROID_LOG_DEFAULT,
  ANDROID_LOG_VERBOSE,
  ANDROID_LOG_DEBUG,
  ANDROID_LOG_INFO,
  ANDROID_LOG_WARN,
  ANDROID_LOG_ERROR,
  ANDROID_LOG_FATAL,
  ANDROID_LOG_SILENT
}
enum
Android log priority values, in increasing order of priority.
log_id{
  LOG_ID_MIN = 0,
  LOG_ID_MAIN = 0,
  LOG_ID_RADIO = 1,
  LOG_ID_EVENTS = 2,
  LOG_ID_SYSTEM = 3,
  LOG_ID_CRASH = 4,
  LOG_ID_STATS = 5,
  LOG_ID_SECURITY = 6,
  LOG_ID_KERNEL = 7,
  LOG_ID_MAX
}
enum
Identifies a specific log buffer for __android_log_buf_write() and __android_log_buf_print().

Typedefs

__android_aborter_function)(const char *abort_message) typedef
void(*
Prototype for the 'abort' function that is called when liblog will abort due to __android_log_assert() failures.
__android_logger_function)(const struct __android_logger_data *logger_data, const char *message) typedef
void(*
Prototype for the 'logger' function that is called for every log message.
android_LogPriority typedef
Android log priority values, in increasing order of priority.
log_id_t typedef
enum log_id
Identifies a specific log buffer for __android_log_buf_write() and __android_log_buf_print().

Functions

__android_log_assert(const char *cond, const char *tag, const char *fmt, ...)
void
Writes an assertion failure to the log (as ANDROID_LOG_FATAL) and to stderr, before calling abort(3).
__android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
int
Writes a formatted string to log buffer id, with priority prio and tag tag.
__android_log_buf_write(int bufID, int prio, const char *tag, const char *text)
int
Writes the constant string text to the log buffer id, with priority prio and tag tag.
__android_log_call_aborter(const char *abort_message)
void
Calls the stored aborter function.
__android_log_default_aborter(const char *abort_message)
void
Sets android_set_abort_message() on device then aborts().
__android_log_get_minimum_priority(void)
int
Gets the minimum priority that will be logged for this process.
__android_log_is_loggable(int prio, const char *tag, int default_prio)
int
Use the per-tag properties "log.tag." along with the minimum priority from __android_log_set_minimum_priority() to determine if a log message with a given prio and tag will be printed.
__android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio)
int
__android_log_logd_logger(const struct __android_logger_data *logger_data, const char *msg)
void
Writes the log message to logd.
__android_log_print(int prio, const char *tag, const char *fmt, ...)
int
Writes a formatted string to the log, with priority prio and tag tag.
__android_log_set_aborter(__android_aborter_function aborter)
void
Sets a user defined aborter function that is called for __android_log_assert() failures.
__android_log_set_default_tag(const char *tag)
void
Sets the default tag if no tag is provided when writing a log message.
__android_log_set_logger(__android_logger_function logger)
void
Sets a user defined logger function.
__android_log_set_minimum_priority(int priority)
int
Sets the minimum priority that will be logged for this process.
__android_log_stderr_logger(const struct __android_logger_data *logger_data, const char *message)
void
Writes the log message to stderr.
__android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
int
Equivalent to __android_log_print, but taking a va_list.
__android_log_write(int prio, const char *tag, const char *text)
int
Writes the constant string text to the log, with priority prio and tag tag.
__android_log_write_logger_data(struct __android_logger_data *logger_data, const char *msg)
void
Writes the log message specified with logger_data and msg to the log.

Structs

__android_logger_data

Logger data struct used for writing log messages to liblog via __android_log_write_logger_data() and sending log messages to user defined loggers specified in __android_log_set_logger().

Enumerations

android_LogPriority

 android_LogPriority

Android log priority values, in increasing order of priority.

Properties
ANDROID_LOG_DEBUG

Debug logging.

Should typically be disabled for a release apk.

ANDROID_LOG_DEFAULT

The default priority, for internal use only.

ANDROID_LOG_ERROR

Error logging.

For use with unrecoverable failures.

ANDROID_LOG_FATAL

Fatal logging.

For use when aborting.

ANDROID_LOG_INFO

Informational logging.

Should typically be disabled for a release apk.

ANDROID_LOG_SILENT

For internal use only.

ANDROID_LOG_UNKNOWN

For internal use only.

ANDROID_LOG_VERBOSE

Verbose logging.

Should typically be disabled for a release apk.

ANDROID_LOG_WARN

Warning logging.

For use with recoverable failures.

log_id

 log_id

Identifies a specific log buffer for __android_log_buf_write() and __android_log_buf_print().

Properties
LOG_ID_CRASH

The crash log buffer.

LOG_ID_EVENTS

The event log buffer.

LOG_ID_KERNEL

The kernel log buffer.

LOG_ID_MAIN

The main log buffer.

This is the only log buffer available to apps.

LOG_ID_MAX
LOG_ID_MIN
LOG_ID_RADIO

The radio log buffer.

LOG_ID_SECURITY

The security log buffer.

LOG_ID_STATS

The statistics log buffer.

LOG_ID_SYSTEM

The system log buffer.

Typedefs

__android_aborter_function

void(* __android_aborter_function)(const char *abort_message)

Prototype for the 'abort' function that is called when liblog will abort due to __android_log_assert() failures.

__android_logger_function

void(* __android_logger_function)(const struct __android_logger_data *logger_data, const char *message)

Prototype for the 'logger' function that is called for every log message.

android_LogPriority

enum android_LogPriority android_LogPriority

Android log priority values, in increasing order of priority.

log_id_t

enum log_id log_id_t

Identifies a specific log buffer for __android_log_buf_write() and __android_log_buf_print().

Functions

__android_log_assert

void __android_log_assert(
  const char *cond,
  const char *tag,
  const char *fmt,
  ...
)

Writes an assertion failure to the log (as ANDROID_LOG_FATAL) and to stderr, before calling abort(3).

If fmt is non-null, cond is unused. If fmt is null, the string Assertion failed: s is used with cond as the string argument. If both fmt and cond are null, a default string is provided.

Most callers should use assert(3) from instead, or the __assert and __assert2 functions provided by bionic if more control is needed. They support automatically including the source filename and line number more conveniently than this function.

__android_log_buf_print

int __android_log_buf_print(
  int bufID,
  int prio,
  const char *tag,
  const char *fmt,
  ...
)

Writes a formatted string to log buffer id, with priority prio and tag tag.

The details of formatting are the same as for printf(3).

Apps should use __android_log_print() instead.

__android_log_buf_write

int __android_log_buf_write(
  int bufID,
  int prio,
  const char *tag,
  const char *text
)

Writes the constant string text to the log buffer id, with priority prio and tag tag.

Apps should use __android_log_write() instead.

__android_log_call_aborter

void __android_log_call_aborter(
  const char *abort_message
)

Calls the stored aborter function.

This allows for other logging libraries to use the same aborter function by calling this function in liblog.

__android_log_default_aborter

void __android_log_default_aborter(
  const char *abort_message
)

Sets android_set_abort_message() on device then aborts().

This is the default aborter.

__android_log_get_minimum_priority

int __android_log_get_minimum_priority(
  void
)

Gets the minimum priority that will be logged for this process.

If none has been set by a previous __android_log_set_minimum_priority() call, this returns ANDROID_LOG_DEFAULT.

__android_log_is_loggable

int __android_log_is_loggable(
  int prio,
  const char *tag,
  int default_prio
)

Use the per-tag properties "log.tag." along with the minimum priority from __android_log_set_minimum_priority() to determine if a log message with a given prio and tag will be printed.

A non-zero result indicates yes, zero indicates false.

If both a priority for a tag and a minimum priority are set by __android_log_set_minimum_priority(), then the lowest of the two values are to determine the minimum priority needed to log. If only one is set, then that value is used to determine the minimum priority needed. If none are set, then default_priority is used.

prio is ANDROID_LOG_VERBOSE to ANDROID_LOG_FATAL.

__android_log_is_loggable_len

int __android_log_is_loggable_len(
  int prio,
  const char *tag,
  size_t len,
  int default_prio
)

__android_log_logd_logger

void __android_log_logd_logger(
  const struct __android_logger_data *logger_data,
  const char *msg
)

Writes the log message to logd.

This is an __android_logger_function and can be provided to __android_log_set_logger(). It is the default logger when running liblog on a device.

__android_log_print

int __android_log_print(
  int prio,
  const char *tag,
  const char *fmt,
  ...
)

Writes a formatted string to the log, with priority prio and tag tag.

The details of formatting are the same as for printf(3).

__android_log_set_aborter

void __android_log_set_aborter(
  __android_aborter_function aborter
)

Sets a user defined aborter function that is called for __android_log_assert() failures.

__android_log_set_default_tag

void __android_log_set_default_tag(
  const char *tag
)

Sets the default tag if no tag is provided when writing a log message.

Defaults to getprogname(). This truncates tag to the maximum log message size, though appropriate tags should be much smaller.

__android_log_set_logger

void __android_log_set_logger(
  __android_logger_function logger
)

Sets a user defined logger function.

All log messages sent to liblog will be set to the function pointer specified by logger for processing.

__android_log_set_minimum_priority

int __android_log_set_minimum_priority(
  int priority
)

Sets the minimum priority that will be logged for this process.

This returns the previous set minimum priority, or ANDROID_LOG_DEFAULT if none was set.

__android_log_stderr_logger

void __android_log_stderr_logger(
  const struct __android_logger_data *logger_data,
  const char *message
)

Writes the log message to stderr.

This is an __android_logger_function and can be provided to __android_log_set_logger(). It is the default logger when running liblog on host.

__android_log_vprint

int __android_log_vprint(
  int prio,
  const char *tag,
  const char *fmt,
  va_list ap
)

Equivalent to __android_log_print, but taking a va_list.

(If __android_log_print is like printf, this is like vprintf.)

__android_log_write

int __android_log_write(
  int prio,
  const char *tag,
  const char *text
)

Writes the constant string text to the log, with priority prio and tag tag.

__android_log_write_logger_data

void __android_log_write_logger_data(
  struct __android_logger_data *logger_data,
  const char *msg
)

Writes the log message specified with logger_data and msg to the log.

logger_data includes additional file name and line number information that a logger may use. logger_data is versioned for backwards compatibility. This assumes that loggability has already been checked through __android_log_is_loggable(). Higher level logging libraries, such as libbase, first check loggability, then format their buffers, then pass the message to liblog via this function, and therefore we do not want to duplicate the loggability check here.