• Home
Name
Date
Size
#Lines
LOC

..--

include/03-May-2024-2,2311,078

include_vndk/03-May-2024-1,044522

rust/03-May-2024-53

tests/03-May-2024-5,4134,025

.clang-formatD03-May-2024239

Android.bpD03-May-20246.1 KiB240221

NOTICED03-May-202410.4 KiB191158

README.mdD03-May-20247.3 KiB162134

README.protocol.mdD03-May-20242.6 KiB9369

event.logtagsD03-May-20241.2 KiB3836

event_tag_map.cppD03-May-202410.5 KiB385293

liblog.map.txtD03-May-20242.6 KiB9486

log_event_list.cppD03-May-202416.5 KiB544452

log_event_write.cppD03-May-20241.4 KiB4927

log_time.cppD03-May-20242.7 KiB130104

logd_reader.cppD03-May-20249.1 KiB385295

logd_reader.hD03-May-2024916 329

logd_writer.cppD03-May-20245.9 KiB206138

logd_writer.hD03-May-2024782 255

logger.hD03-May-20241.3 KiB5221

logger_name.cppD03-May-20241.9 KiB7343

logger_read.cppD03-May-20243.9 KiB150100

logger_write.cppD03-May-202416.4 KiB589434

logger_write.hD03-May-2024684 223

logprint.cppD03-May-202449.1 KiB1,7131,295

pmsg_reader.cppD03-May-202413.2 KiB468369

pmsg_reader.hD03-May-2024851 308

pmsg_writer.cppD03-May-20246.8 KiB256161

pmsg_writer.hD03-May-2024782 255

properties.cppD03-May-20249.8 KiB354252

uio.hD03-May-2024763 2810

README.md

1 Android liblog
2 --------------
3 
4 Public Functions and Macros
5 ---------------------------
6 
7     /*
8      * Please limit to 24 characters for runtime is loggable,
9      * 16 characters for persist is loggable, and logcat pretty
10      * alignment with limit of 7 characters.
11     */
12     #define LOG_TAG "yourtag"
13     #include <log/log.h>
14 
15     ALOG(android_priority, tag, format, ...)
16     IF_ALOG(android_priority, tag)
17     LOG_PRI(priority, tag, format, ...)
18     LOG_PRI_VA(priority, tag, format, args)
19     #define LOG_TAG NULL
20     ALOGV(format, ...)
21     SLOGV(format, ...)
22     RLOGV(format, ...)
23     ALOGV_IF(cond, format, ...)
24     SLOGV_IF(cond, format, ...)
25     RLOGV_IF(cond, format, ...)
26     IF_ALOGC()
27     ALOGD(format, ...)
28     SLOGD(format, ...)
29     RLOGD(format, ...)
30     ALOGD_IF(cond, format, ...)
31     SLOGD_IF(cond, format, ...)
32     RLOGD_IF(cond, format, ...)
33     IF_ALOGD()
34     ALOGI(format, ...)
35     SLOGI(format, ...)
36     RLOGI(format, ...)
37     ALOGI_IF(cond, format, ...)
38     SLOGI_IF(cond, format, ...)
39     RLOGI_IF(cond, format, ...)
40     IF_ALOGI()
41     ALOGW(format, ...)
42     SLOGW(format, ...)
43     RLOGW(format, ...)
44     ALOGW_IF(cond, format, ...)
45     SLOGW_IF(cond, format, ...)
46     RLOGW_IF(cond, format, ...)
47     IF_ALOGW()
48     ALOGE(format, ...)
49     SLOGE(format, ...)
50     RLOGE(format, ...)
51     ALOGE_IF(cond, format, ...)
52     SLOGE_IF(cond, format, ...)
53     RLOGE_IF(cond, format, ...)
54     IF_ALOGE()
55     LOG_FATAL(format, ...)
56     LOG_ALWAYS_FATAL(format, ...)
57     LOG_FATAL_IF(cond, format, ...)
58     LOG_ALWAYS_FATAL_IF(cond, format, ...)
59     ALOG_ASSERT(cond, format, ...)
60     LOG_EVENT_INT(tag, value)
61     LOG_EVENT_LONG(tag, value)
62 
63     log_id_t android_logger_get_id(struct logger *logger)
64     int android_logger_clear(struct logger *logger)
65     int android_logger_get_log_size(struct logger *logger)
66     int android_logger_get_log_readable_size(struct logger *logger)
67     int android_logger_get_log_version(struct logger *logger)
68 
69     struct logger_list *android_logger_list_alloc(int mode, unsigned int tail, pid_t pid)
70     struct logger *android_logger_open(struct logger_list *logger_list, log_id_t id)
71     struct logger_list *android_logger_list_open(log_id_t id, int mode, unsigned int tail, pid_t pid)
72     int android_logger_list_read(struct logger_list *logger_list, struct log_msg *log_msg)
73     void android_logger_list_free(struct logger_list *logger_list)
74 
75     log_id_t android_name_to_log_id(const char *logName)
76     const char *android_log_id_to_name(log_id_t log_id)
77 
78     android_log_context create_android_logger(uint32_t tag)
79 
80     int android_log_write_list_begin(android_log_context ctx)
81     int android_log_write_list_end(android_log_context ctx)
82 
83     int android_log_write_int32(android_log_context ctx, int32_t value)
84     int android_log_write_int64(android_log_context ctx, int64_t value)
85     int android_log_write_string8(android_log_context ctx, const char *value)
86     int android_log_write_string8_len(android_log_context ctx, const char *value, size_t maxlen)
87     int android_log_write_float32(android_log_context ctx, float value)
88 
89     int android_log_write_list(android_log_context ctx, log_id_t id = LOG_ID_EVENTS)
90 
91     android_log_context create_android_log_parser(const char *msg, size_t len)
92     android_log_list_element android_log_read_next(android_log_context ctx)
93     android_log_list_element android_log_peek_next(android_log_context ctx)
94 
95     int android_log_destroy(android_log_context *ctx)
96 
97 Description
98 -----------
99 
100 liblog represents an interface to the volatile Android Logging system for NDK (Native) applications
101 and libraries.  Interfaces for either writing or reading logs.  The log buffers are divided up in
102 Main, System, Radio and Events sub-logs.
103 
104 The logging interfaces are a series of macros, all of which can be overridden individually in order
105 to control the verbosity of the application or library.  `[ASR]LOG[VDIWE]` calls are used to log to
106 Basic, System or Radio sub-logs in either the Verbose, Debug, Info, Warning or Error priorities.
107 `[ASR]LOG[VDIWE]_IF` calls are used to perform thus based on a condition being true.
108 `IF_ALOG[VDIWE]` calls are true if the current `LOG_TAG` is enabled at the specified priority.
109 `LOG_ALWAYS_FATAL` is used to `ALOG` a message, then kill the process.  `LOG_FATAL` call is a
110 variant of `LOG_ALWAYS_FATAL`, only enabled in engineering, and not release builds.  `ALOG_ASSERT`
111 is used to `ALOG` a message if the condition is false; the condition is part of the logged message.
112 `LOG_EVENT_(INT|LONG)` is used to drop binary content into the Events sub-log.
113 
114 The log reading interfaces permit opening the logs either singly or multiply, retrieving a log entry
115 at a time in time sorted order, optionally limited to a specific pid and tail of the log(s) and
116 finally a call closing the logs.  A single log can be opened with `android_logger_list_open()`; or
117 multiple logs can be opened with `android_logger_list_alloc()`, calling in turn the
118 `android_logger_open()` for each log id.  Each entry can be retrieved with
119 `android_logger_list_read()`.  The log(s) can be closed with `android_logger_list_free()`.
120 `ANDROID_LOG_NONBLOCK` mode will report when the log reading is done with an `EAGAIN` error return
121 code, otherwise the `android_logger_list_read()` call will block for new entries.
122 
123 The `ANDROID_LOG_WRAP` mode flag to the `android_logger_list_alloc_time()` signals logd to quiesce
124 the reader until the buffer is about to prune at the start time then proceed to dumping content.
125 
126 The `ANDROID_LOG_PSTORE` mode flag to the `android_logger_open()` is used to switch from the active
127 logs to the persistent logs from before the last reboot.
128 
129 The value returned by `android_logger_open()` can be used as a parameter to the
130 `android_logger_clear()` function to empty the sub-log.
131 
132 The value returned by `android_logger_open()` can be used as a parameter to the
133 `android_logger_get_log_(size|readable_size|version)` to retrieve the sub-log maximum size, readable
134 size and log buffer format protocol version respectively.  `android_logger_get_id()` returns the id
135 that was used when opening the sub-log.
136 
137 Errors
138 ------
139 
140 If messages fail, a negative error code will be returned to the caller.
141 
142 The `-ENOTCONN` return code indicates that the logger daemon is stopped.
143 
144 The `-EBADF` return code indicates that the log access point can not be opened, or the log buffer id
145 is out of range.
146 
147 For the `-EAGAIN` return code, this means that the logging message was temporarily backed-up either
148 because of Denial Of Service (DOS) logging pressure from some spammy application or service in the
149 Android system, or if too small of a value is set in /proc/sys/net/unix/max_dgram_qlen.  To aid in
150 diagnosing the occurence of this, a binary event from liblog will be sent to the log daemon once a
151 new message can get through indicating how many messages were dropped as a result.  Please take
152 action to resolve the structural problems at the source.
153 
154 It is generally not advised for the caller to retry the `-EAGAIN` return code as this will only make
155 the problem(s) worse and cause your application to temporarily drop to the logger daemon priority,
156 BATCH scheduling policy and background task cgroup. If you require a group of messages to be passed
157 atomically, merge them into one message with embedded newlines to the maximum length
158 `LOGGER_ENTRY_MAX_PAYLOAD`.
159 
160 Other return codes from writing operation can be returned.  Since the library retries on `EINTR`,
161 `-EINTR` should never be returned.
162 

README.protocol.md

1 # liblog -> logd
2 
3 The data that liblog sends to logd is represented below.
4 
5     struct {
6         android_log_header_t header;
7         union {
8            struct {
9                 char     prio;
10                 char     tag[...];
11                 char     message[...];
12             } string;
13             struct {
14                 android_event_header_t event_header;
15                 android_event_*_t      payload[...];
16             } binary;
17         };
18     };
19 
20 where the embedded structs are defined as:
21 
22     struct android_log_header_t {
23         uint8_t id;
24         uint16_t tid;
25         log_time realtime;
26     };
27 
28     struct log_time {
29         uint32_t tv_sec = 0;
30         uint32_t tv_nsec = 0;
31     }
32 
33     struct android_event_header_t {
34         int32_t tag;
35     };
36 
37     struct android_event_list_t {
38         int8_t type;  // EVENT_TYPE_LIST
39         int8_t element_count;
40     };
41 
42     struct android_event_float_t {
43         int8_t type;  // EVENT_TYPE_FLOAT
44         float data;
45     };
46 
47     struct android_event_int_t {
48         int8_t type;   // EVENT_TYPE_INT
49         int32_t data;
50     } android_event_int_t;
51 
52     struct android_event_long_t {
53         int8_t type;   // EVENT_TYPE_LONG
54         int64_t data;
55     };
56 
57     struct android_event_string_t {
58         int8_t type;     // EVENT_TYPE_STRING;
59         int32_t length;
60         char data[];
61     };
62 
63 The payload, excluding the header, has a max size of LOGGER_ENTRY_MAX_PAYLOAD.
64 
65 ## header
66 
67 The header is added immediately before sending the log message to logd.
68 
69 ## `string` payload
70 
71 The `string` part of the union is for normal buffers (main, system, radio, etc) and consists of a
72 single character priority, followed by a variable length null terminated string for the tag, and
73 finally a variable length null terminated string for the message.
74 
75 This payload is used for the `__android_log_buf_write()` family of functions.
76 
77 ## `binary` payload
78 
79 The `binary` part of the union is for binary buffers (events, security, etc) and consists of an
80 android_event_header_t struct followed by a variable number of android_event_*_t
81 (android_event_list_t, android_event_int_t, etc) structs.
82 
83 If multiple android_event_*_t elements are present, then they must be in a list and the first
84 element in payload must be an android_event_list_t.
85 
86 This payload is used for the `__android_log_bwrite()` family of functions. It is additionally used
87 for `android_log_write_list()` and the related functions that manipulate event lists.
88 
89 # logd -> liblog
90 
91 logd sends a `logger_entry` struct to liblog followed by the payload. The payload is identical to
92 the payloads defined above. The max size of the entire message from logd is LOGGER_ENTRY_MAX_LEN.
93