platform_system_core/liblog
Tom Cherry b47aa2a592 liblog: remove more unused code
Cleanup the headers; we really don't want to encourage any more
cutils/list.h usage...

Remove __android_log_uid() since the only remaining users are built
for device, so they can just use getuid() directly.

Test: build
Change-Id: I62be2c1e43d83807deaa9342afcc72459947cf15
2020-01-08 17:11:09 -08:00
..
include Make android_logger_set_prune_list() sane 2019-12-06 11:23:58 -08:00
include_vndk Revert "liblog: remove mistakenly added symbols from vndk" 2019-10-23 11:39:13 -07:00
tests CtsLiblogTestCases secondary_user 2020-01-06 09:58:07 -08:00
.clang-format Use the existing .clang-format-2 for liblog 2019-01-09 13:08:10 -08:00
Android.bp liblog: don't destroy global mutexes 2019-12-20 16:13:00 -08:00
event.logtags liblog: logprint supports number of seconds time event field 2017-04-14 12:54:25 -07:00
event_tag_map.cpp liblog: simplify logd 'command' functions and struct logger 2019-11-18 07:16:40 -08:00
fake_log_device.cpp liblog: remove the last of the transport structs 2020-01-08 17:11:06 -08:00
fake_log_device.h liblog: remove the last of the transport structs 2020-01-08 17:11:06 -08:00
liblog.map.txt Rename # vndk tag to # llndk 2019-11-13 14:32:44 +09:00
log_event_list.cpp liblog: cleanup opaque type usage 2019-11-14 10:40:42 -08:00
log_event_write.cpp liblog: remove visibility macros 2019-02-08 11:48:19 -08:00
log_portability.h liblog: remove LIBLOG_WEAK 2019-04-24 17:24:23 -07:00
log_time.cpp liblog: remove visibility macros 2019-02-08 11:48:19 -08:00
logd_reader.cpp liblog: remove more unused code 2020-01-08 17:11:09 -08:00
logd_reader.h liblog: remove the rest of the log reader transport 2019-11-19 09:41:49 -08:00
logd_writer.cpp liblog: remove more unused code 2020-01-08 17:11:09 -08:00
logd_writer.h liblog: remove the last of the transport structs 2020-01-08 17:11:06 -08:00
logger.h liblog: remove more unused code 2020-01-08 17:11:09 -08:00
logger_name.cpp liblog: don't return 0xFFFFFFFF as an invalid log id. 2019-03-25 16:41:39 -07:00
logger_read.cpp liblog: remove more unused code 2020-01-08 17:11:09 -08:00
logger_write.cpp liblog: remove more unused code 2020-01-08 17:11:09 -08:00
logprint.cpp Remove old logger_entry_v* formats 2019-10-24 10:53:14 -07:00
NOTICE liblog: update timestamp on NOTICE file 2014-01-27 15:20:59 -08:00
OWNERS Add OWNERS. 2017-12-07 13:30:03 -08:00
pmsg_reader.cpp liblog: remove more unused code 2020-01-08 17:11:09 -08:00
pmsg_reader.h liblog: remove the rest of the log reader transport 2019-11-19 09:41:49 -08:00
pmsg_writer.cpp liblog: remove more unused code 2020-01-08 17:11:09 -08:00
pmsg_writer.h liblog: remove the last of the transport structs 2020-01-08 17:11:06 -08:00
properties.cpp liblog: remove visibility macros 2019-02-08 11:48:19 -08:00
README.md liblog: remove log/log_transport.h 2019-10-01 08:14:40 -07:00
README.protocol.md liblog: document the liblog<->logd protocol format 2019-10-24 11:19:06 -07:00
rwlock.h liblog: use a rwlock for writer initialization 2019-12-12 16:19:08 -08:00
uio.h Remove liblog/uio.c and <log/uio.h> 2019-01-16 14:26:36 -08:00

Android liblog

Public Functions and Macros

/*
 * Please limit to 24 characters for runtime is loggable,
 * 16 characters for persist is loggable, and logcat pretty
 * alignment with limit of 7 characters.
*/
#define LOG_TAG "yourtag"
#include <log/log.h>

ALOG(android_priority, tag, format, ...)
IF_ALOG(android_priority, tag)
LOG_PRI(priority, tag, format, ...)
LOG_PRI_VA(priority, tag, format, args)
#define LOG_TAG NULL
ALOGV(format, ...)
SLOGV(format, ...)
RLOGV(format, ...)
ALOGV_IF(cond, format, ...)
SLOGV_IF(cond, format, ...)
RLOGV_IF(cond, format, ...)
IF_ALOGC()
ALOGD(format, ...)
SLOGD(format, ...)
RLOGD(format, ...)
ALOGD_IF(cond, format, ...)
SLOGD_IF(cond, format, ...)
RLOGD_IF(cond, format, ...)
IF_ALOGD()
ALOGI(format, ...)
SLOGI(format, ...)
RLOGI(format, ...)
ALOGI_IF(cond, format, ...)
SLOGI_IF(cond, format, ...)
RLOGI_IF(cond, format, ...)
IF_ALOGI()
ALOGW(format, ...)
SLOGW(format, ...)
RLOGW(format, ...)
ALOGW_IF(cond, format, ...)
SLOGW_IF(cond, format, ...)
RLOGW_IF(cond, format, ...)
IF_ALOGW()
ALOGE(format, ...)
SLOGE(format, ...)
RLOGE(format, ...)
ALOGE_IF(cond, format, ...)
SLOGE_IF(cond, format, ...)
RLOGE_IF(cond, format, ...)
IF_ALOGE()
LOG_FATAL(format, ...)
LOG_ALWAYS_FATAL(format, ...)
LOG_FATAL_IF(cond, format, ...)
LOG_ALWAYS_FATAL_IF(cond, format, ...)
ALOG_ASSERT(cond, format, ...)
LOG_EVENT_INT(tag, value)
LOG_EVENT_LONG(tag, value)

clockid_t android_log_clockid()

log_id_t android_logger_get_id(struct logger *logger)
int android_logger_clear(struct logger *logger)
int android_logger_get_log_size(struct logger *logger)
int android_logger_get_log_readable_size(struct logger *logger)
int android_logger_get_log_version(struct logger *logger)

struct logger_list *android_logger_list_alloc(int mode, unsigned int tail, pid_t pid)
struct logger *android_logger_open(struct logger_list *logger_list, log_id_t id)
struct logger_list *android_logger_list_open(log_id_t id, int mode, unsigned int tail, pid_t pid)
int android_logger_list_read(struct logger_list *logger_list, struct log_msg *log_msg)
void android_logger_list_free(struct logger_list *logger_list)

log_id_t android_name_to_log_id(const char *logName)
const char *android_log_id_to_name(log_id_t log_id)

android_log_context create_android_logger(uint32_t tag)

int android_log_write_list_begin(android_log_context ctx)
int android_log_write_list_end(android_log_context ctx)

int android_log_write_int32(android_log_context ctx, int32_t value)
int android_log_write_int64(android_log_context ctx, int64_t value)
int android_log_write_string8(android_log_context ctx, const char *value)
int android_log_write_string8_len(android_log_context ctx, const char *value, size_t maxlen)
int android_log_write_float32(android_log_context ctx, float value)

int android_log_write_list(android_log_context ctx, log_id_t id = LOG_ID_EVENTS)

android_log_context create_android_log_parser(const char *msg, size_t len)
android_log_list_element android_log_read_next(android_log_context ctx)
android_log_list_element android_log_peek_next(android_log_context ctx)

int android_log_destroy(android_log_context *ctx)

Description

liblog represents an interface to the volatile Android Logging system for NDK (Native) applications and libraries. Interfaces for either writing or reading logs. The log buffers are divided up in Main, System, Radio and Events sub-logs.

The logging interfaces are a series of macros, all of which can be overridden individually in order to control the verbosity of the application or library. [ASR]LOG[VDIWE] calls are used to log to BAsic, System or Radio sub-logs in either the Verbose, Debug, Info, Warning or Error priorities. [ASR]LOG[VDIWE]_IF calls are used to perform thus based on a condition being true. IF_ALOG[VDIWE] calls are true if the current LOG_TAG is enabled at the specified priority. LOG_ALWAYS_FATAL is used to ALOG a message, then kill the process. LOG_FATAL call is a variant of LOG_ALWAYS_FATAL, only enabled in engineering, and not release builds. ALOG_ASSERT is used to ALOG a message if the condition is false; the condition is part of the logged message. LOG_EVENT_(INT|LONG) is used to drop binary content into the Events sub-log.

The log reading interfaces permit opening the logs either singly or multiply, retrieving a log entry at a time in time sorted order, optionally limited to a specific pid and tail of the log(s) and finally a call closing the logs. A single log can be opened with android_logger_list_open(); or multiple logs can be opened with android_logger_list_alloc(), calling in turn the android_logger_open() for each log id. Each entry can be retrieved with android_logger_list_read(). The log(s) can be closed with android_logger_list_free(). The logs should be opened with an ANDROID_LOG_RDONLY mode. ANDROID_LOG_NONBLOCK mode will report when the log reading is done with an EAGAIN error return code, otherwise the android_logger_list_read() call will block for new entries.

The ANDROID_LOG_WRAP mode flag to the android_logger_list_alloc_time() signals logd to quiesce the reader until the buffer is about to prune at the start time then proceed to dumping content.

The ANDROID_LOG_PSTORE mode flag to the android_logger_open() is used to switch from the active logs to the persistent logs from before the last reboot.

The value returned by android_logger_open() can be used as a parameter to the android_logger_clear() function to empty the sub-log. It is recommended to only open log ANDROID_LOG_WRONLY in that case.

The value returned by android_logger_open() can be used as a parameter to the android_logger_get_log_(size|readable_size|version) to retrieve the sub-log maximum size, readable size and log buffer format protocol version respectively. android_logger_get_id() returns the id that was used when opening the sub-log. It is recommended to open the log ANDROID_LOG_RDONLY in these cases.

Errors

If messages fail, a negative error code will be returned to the caller.

The -ENOTCONN return code indicates that the logger daemon is stopped.

The -EBADF return code indicates that the log access point can not be opened, or the log buffer id is out of range.

For the -EAGAIN return code, this means that the logging message was temporarily backed-up either because of Denial Of Service (DOS) logging pressure from some chatty application or service in the Android system, or if too small of a value is set in /proc/sys/net/unix/max_dgram_qlen. To aid in diagnosing the occurence of this, a binary event from liblog will be sent to the log daemon once a new message can get through indicating how many messages were dropped as a result. Please take action to resolve the structural problems at the source.

It is generally not advised for the caller to retry the -EAGAIN return code as this will only make the problem(s) worse and cause your application to temporarily drop to the logger daemon priority, BATCH scheduling policy and background task cgroup. If you require a group of messages to be passed atomically, merge them into one message with embedded newlines to the maximum length LOGGER_ENTRY_MAX_PAYLOAD.

Other return codes from writing operation can be returned. Since the library retries on EINTR, -EINTR should never be returned.