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