David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _ANDROID_LOG_H |
| 18 | #define _ANDROID_LOG_H |
| 19 | |
| 20 | /****************************************************************** |
| 21 | * |
| 22 | * IMPORTANT NOTICE: |
| 23 | * |
| 24 | * This file is part of Android's set of stable system headers |
| 25 | * exposed by the Android NDK (Native Development Kit) since |
| 26 | * platform release 1.5 |
| 27 | * |
| 28 | * Third-party source AND binary code relies on the definitions |
| 29 | * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. |
| 30 | * |
| 31 | * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) |
| 32 | * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS |
| 33 | * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY |
| 34 | * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Support routines to send messages to the Android in-kernel log buffer, |
| 39 | * which can later be accessed through the 'logcat' utility. |
| 40 | * |
| 41 | * Each log message must have |
| 42 | * - a priority |
| 43 | * - a log tag |
| 44 | * - some text |
| 45 | * |
| 46 | * The tag normally corresponds to the component that emits the log message, |
| 47 | * and should be reasonably small. |
| 48 | * |
| 49 | * Log message text may be truncated to less than an implementation-specific |
| 50 | * limit (e.g. 1023 characters max). |
| 51 | * |
| 52 | * Note that a newline character ("\n") will be appended automatically to your |
| 53 | * log message, if not already there. It is not possible to send several messages |
| 54 | * and have them appear on a single line in logcat. |
| 55 | * |
| 56 | * PLEASE USE LOGS WITH MODERATION: |
| 57 | * |
| 58 | * - Sending log messages eats CPU and slow down your application and the |
| 59 | * system. |
| 60 | * |
| 61 | * - The circular log buffer is pretty small (<64KB), sending many messages |
| 62 | * might push off other important log messages from the rest of the system. |
| 63 | * |
| 64 | * - In release builds, only send log messages to account for exceptional |
| 65 | * conditions. |
| 66 | * |
| 67 | * NOTE: These functions MUST be implemented by /system/lib/liblog.so |
| 68 | */ |
| 69 | |
Mark Salyzyn | 6584d0a | 2016-09-28 13:26:55 -0700 | [diff] [blame] | 70 | #if !defined(_WIN32) |
| 71 | #include <pthread.h> |
| 72 | #endif |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 73 | #include <stdarg.h> |
Mark Salyzyn | 6584d0a | 2016-09-28 13:26:55 -0700 | [diff] [blame] | 74 | #include <stdint.h> |
| 75 | #include <stdio.h> |
| 76 | #include <sys/types.h> |
| 77 | #include <time.h> |
| 78 | #include <unistd.h> |
| 79 | |
| 80 | #include <log/uio.h> |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 81 | |
| 82 | #ifdef __cplusplus |
| 83 | extern "C" { |
| 84 | #endif |
| 85 | |
| 86 | /* |
| 87 | * Android log priority values, in ascending priority order. |
| 88 | */ |
| 89 | typedef enum android_LogPriority { |
| 90 | ANDROID_LOG_UNKNOWN = 0, |
| 91 | ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ |
| 92 | ANDROID_LOG_VERBOSE, |
| 93 | ANDROID_LOG_DEBUG, |
| 94 | ANDROID_LOG_INFO, |
| 95 | ANDROID_LOG_WARN, |
| 96 | ANDROID_LOG_ERROR, |
| 97 | ANDROID_LOG_FATAL, |
| 98 | ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ |
| 99 | } android_LogPriority; |
| 100 | |
| 101 | /* |
Mark Salyzyn | df7a4c6 | 2016-08-23 10:23:36 -0700 | [diff] [blame] | 102 | * Release any logger resources (a new log write will immediately re-acquire) |
| 103 | */ |
| 104 | void __android_log_close(); |
| 105 | |
| 106 | /* |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 107 | * Send a simple string to the log. |
| 108 | */ |
| 109 | int __android_log_write(int prio, const char *tag, const char *text); |
| 110 | |
| 111 | /* |
| 112 | * Send a formatted string to the log, used like printf(fmt,...) |
| 113 | */ |
| 114 | int __android_log_print(int prio, const char *tag, const char *fmt, ...) |
| 115 | #if defined(__GNUC__) |
Dan Willemsen | 0cddcc6 | 2014-06-11 15:36:58 -0700 | [diff] [blame] | 116 | #ifdef __USE_MINGW_ANSI_STDIO |
Andrew Hsieh | ad83285 | 2014-05-09 11:50:45 +0800 | [diff] [blame] | 117 | #if __USE_MINGW_ANSI_STDIO |
| 118 | __attribute__ ((format(gnu_printf, 3, 4))) |
| 119 | #else |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 120 | __attribute__ ((format(printf, 3, 4))) |
| 121 | #endif |
Dan Willemsen | 0cddcc6 | 2014-06-11 15:36:58 -0700 | [diff] [blame] | 122 | #else |
| 123 | __attribute__ ((format(printf, 3, 4))) |
| 124 | #endif |
Andrew Hsieh | ad83285 | 2014-05-09 11:50:45 +0800 | [diff] [blame] | 125 | #endif |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 126 | ; |
| 127 | |
| 128 | /* |
| 129 | * A variant of __android_log_print() that takes a va_list to list |
| 130 | * additional parameters. |
| 131 | */ |
| 132 | int __android_log_vprint(int prio, const char *tag, |
| 133 | const char *fmt, va_list ap); |
| 134 | |
| 135 | /* |
Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 136 | * Log an assertion failure and abort the process to have a chance |
| 137 | * to inspect it if a debugger is attached. This uses the FATAL priority. |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 138 | */ |
| 139 | void __android_log_assert(const char *cond, const char *tag, |
Elliott Hughes | da6b2e2 | 2014-04-23 14:57:32 -0700 | [diff] [blame] | 140 | const char *fmt, ...) |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 141 | #if defined(__GNUC__) |
Elliott Hughes | 665051c | 2016-06-20 17:21:59 -0700 | [diff] [blame] | 142 | __attribute__ ((__noreturn__)) |
Dan Willemsen | 0cddcc6 | 2014-06-11 15:36:58 -0700 | [diff] [blame] | 143 | #ifdef __USE_MINGW_ANSI_STDIO |
Andrew Hsieh | ad83285 | 2014-05-09 11:50:45 +0800 | [diff] [blame] | 144 | #if __USE_MINGW_ANSI_STDIO |
| 145 | __attribute__ ((format(gnu_printf, 3, 4))) |
| 146 | #else |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 147 | __attribute__ ((format(printf, 3, 4))) |
| 148 | #endif |
Dan Willemsen | 0cddcc6 | 2014-06-11 15:36:58 -0700 | [diff] [blame] | 149 | #else |
| 150 | __attribute__ ((format(printf, 3, 4))) |
| 151 | #endif |
Andrew Hsieh | ad83285 | 2014-05-09 11:50:45 +0800 | [diff] [blame] | 152 | #endif |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 153 | ; |
| 154 | |
Mark Salyzyn | 6584d0a | 2016-09-28 13:26:55 -0700 | [diff] [blame] | 155 | // |
| 156 | // C/C++ logging functions. See the logging documentation for API details. |
| 157 | // |
| 158 | // We'd like these to be available from C code (in case we import some from |
| 159 | // somewhere), so this has a C interface. |
| 160 | // |
| 161 | // The output will be correct when the log file is shared between multiple |
| 162 | // threads and/or multiple processes so long as the operating system |
| 163 | // supports O_APPEND. These calls have mutex-protected data structures |
| 164 | // and so are NOT reentrant. Do not use LOG in a signal handler. |
| 165 | // |
| 166 | |
| 167 | // This file uses ", ## __VA_ARGS__" zero-argument token pasting to |
| 168 | // work around issues with debug-only syntax errors in assertions |
| 169 | // that are missing format strings. See commit |
| 170 | // 19299904343daf191267564fe32e6cd5c165cd42 |
| 171 | #if defined(__clang__) |
| 172 | #pragma clang diagnostic push |
| 173 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" |
| 174 | #endif |
| 175 | |
| 176 | int __android_log_bwrite(int32_t tag, const void *payload, size_t len); |
| 177 | int __android_log_btwrite(int32_t tag, char type, const void *payload, |
| 178 | size_t len); |
| 179 | int __android_log_bswrite(int32_t tag, const char *payload); |
| 180 | |
| 181 | int __android_log_security_bwrite(int32_t tag, const void *payload, size_t len); |
| 182 | int __android_log_security_bswrite(int32_t tag, const char *payload); |
| 183 | |
| 184 | // --------------------------------------------------------------------- |
| 185 | |
| 186 | /* |
| 187 | * Normally we strip ALOGV (VERBOSE messages) from release builds. |
| 188 | * You can modify this (for example with "#define LOG_NDEBUG 0" |
| 189 | * at the top of your source file) to change that behavior. |
| 190 | */ |
| 191 | #ifndef LOG_NDEBUG |
| 192 | #ifdef NDEBUG |
| 193 | #define LOG_NDEBUG 1 |
| 194 | #else |
| 195 | #define LOG_NDEBUG 0 |
| 196 | #endif |
| 197 | #endif |
| 198 | |
| 199 | /* |
| 200 | * This is the local tag used for the following simplified |
| 201 | * logging macros. You can change this preprocessor definition |
| 202 | * before using the other macros to change the tag. |
| 203 | */ |
| 204 | #ifndef LOG_TAG |
| 205 | #define LOG_TAG NULL |
| 206 | #endif |
| 207 | |
| 208 | // --------------------------------------------------------------------- |
| 209 | |
| 210 | #ifndef __predict_false |
| 211 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) |
| 212 | #endif |
| 213 | |
| 214 | /* |
| 215 | * -DLINT_RLOG in sources that you want to enforce that all logging |
| 216 | * goes to the radio log buffer. If any logging goes to any of the other |
| 217 | * log buffers, there will be a compile or link error to highlight the |
| 218 | * problem. This is not a replacement for a full audit of the code since |
| 219 | * this only catches compiled code, not ifdef'd debug code. Options to |
| 220 | * defining this, either temporarily to do a spot check, or permanently |
| 221 | * to enforce, in all the communications trees; We have hopes to ensure |
| 222 | * that by supplying just the radio log buffer that the communications |
| 223 | * teams will have their one-stop shop for triaging issues. |
| 224 | */ |
| 225 | #ifndef LINT_RLOG |
| 226 | |
| 227 | /* |
| 228 | * Simplified macro to send a verbose log message using the current LOG_TAG. |
| 229 | */ |
| 230 | #ifndef ALOGV |
| 231 | #define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) |
| 232 | #if LOG_NDEBUG |
| 233 | #define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0) |
| 234 | #else |
| 235 | #define ALOGV(...) __ALOGV(__VA_ARGS__) |
| 236 | #endif |
| 237 | #endif |
| 238 | |
| 239 | #ifndef ALOGV_IF |
| 240 | #if LOG_NDEBUG |
| 241 | #define ALOGV_IF(cond, ...) ((void)0) |
| 242 | #else |
| 243 | #define ALOGV_IF(cond, ...) \ |
| 244 | ( (__predict_false(cond)) \ |
| 245 | ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ |
| 246 | : (void)0 ) |
| 247 | #endif |
| 248 | #endif |
| 249 | |
| 250 | /* |
| 251 | * Simplified macro to send a debug log message using the current LOG_TAG. |
| 252 | */ |
| 253 | #ifndef ALOGD |
| 254 | #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) |
| 255 | #endif |
| 256 | |
| 257 | #ifndef ALOGD_IF |
| 258 | #define ALOGD_IF(cond, ...) \ |
| 259 | ( (__predict_false(cond)) \ |
| 260 | ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ |
| 261 | : (void)0 ) |
| 262 | #endif |
| 263 | |
| 264 | /* |
| 265 | * Simplified macro to send an info log message using the current LOG_TAG. |
| 266 | */ |
| 267 | #ifndef ALOGI |
| 268 | #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) |
| 269 | #endif |
| 270 | |
| 271 | #ifndef ALOGI_IF |
| 272 | #define ALOGI_IF(cond, ...) \ |
| 273 | ( (__predict_false(cond)) \ |
| 274 | ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ |
| 275 | : (void)0 ) |
| 276 | #endif |
| 277 | |
| 278 | /* |
| 279 | * Simplified macro to send a warning log message using the current LOG_TAG. |
| 280 | */ |
| 281 | #ifndef ALOGW |
| 282 | #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) |
| 283 | #endif |
| 284 | |
| 285 | #ifndef ALOGW_IF |
| 286 | #define ALOGW_IF(cond, ...) \ |
| 287 | ( (__predict_false(cond)) \ |
| 288 | ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ |
| 289 | : (void)0 ) |
| 290 | #endif |
| 291 | |
| 292 | /* |
| 293 | * Simplified macro to send an error log message using the current LOG_TAG. |
| 294 | */ |
| 295 | #ifndef ALOGE |
| 296 | #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) |
| 297 | #endif |
| 298 | |
| 299 | #ifndef ALOGE_IF |
| 300 | #define ALOGE_IF(cond, ...) \ |
| 301 | ( (__predict_false(cond)) \ |
| 302 | ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ |
| 303 | : (void)0 ) |
| 304 | #endif |
| 305 | |
| 306 | // --------------------------------------------------------------------- |
| 307 | |
| 308 | /* |
| 309 | * Conditional based on whether the current LOG_TAG is enabled at |
| 310 | * verbose priority. |
| 311 | */ |
| 312 | #ifndef IF_ALOGV |
| 313 | #if LOG_NDEBUG |
| 314 | #define IF_ALOGV() if (false) |
| 315 | #else |
| 316 | #define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG) |
| 317 | #endif |
| 318 | #endif |
| 319 | |
| 320 | /* |
| 321 | * Conditional based on whether the current LOG_TAG is enabled at |
| 322 | * debug priority. |
| 323 | */ |
| 324 | #ifndef IF_ALOGD |
| 325 | #define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG) |
| 326 | #endif |
| 327 | |
| 328 | /* |
| 329 | * Conditional based on whether the current LOG_TAG is enabled at |
| 330 | * info priority. |
| 331 | */ |
| 332 | #ifndef IF_ALOGI |
| 333 | #define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG) |
| 334 | #endif |
| 335 | |
| 336 | /* |
| 337 | * Conditional based on whether the current LOG_TAG is enabled at |
| 338 | * warn priority. |
| 339 | */ |
| 340 | #ifndef IF_ALOGW |
| 341 | #define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG) |
| 342 | #endif |
| 343 | |
| 344 | /* |
| 345 | * Conditional based on whether the current LOG_TAG is enabled at |
| 346 | * error priority. |
| 347 | */ |
| 348 | #ifndef IF_ALOGE |
| 349 | #define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG) |
| 350 | #endif |
| 351 | |
| 352 | |
| 353 | // --------------------------------------------------------------------- |
| 354 | |
| 355 | /* |
| 356 | * Simplified macro to send a verbose system log message using the current LOG_TAG. |
| 357 | */ |
| 358 | #ifndef SLOGV |
| 359 | #define __SLOGV(...) \ |
| 360 | ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) |
| 361 | #if LOG_NDEBUG |
| 362 | #define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0) |
| 363 | #else |
| 364 | #define SLOGV(...) __SLOGV(__VA_ARGS__) |
| 365 | #endif |
| 366 | #endif |
| 367 | |
| 368 | #ifndef SLOGV_IF |
| 369 | #if LOG_NDEBUG |
| 370 | #define SLOGV_IF(cond, ...) ((void)0) |
| 371 | #else |
| 372 | #define SLOGV_IF(cond, ...) \ |
| 373 | ( (__predict_false(cond)) \ |
| 374 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ |
| 375 | : (void)0 ) |
| 376 | #endif |
| 377 | #endif |
| 378 | |
| 379 | /* |
| 380 | * Simplified macro to send a debug system log message using the current LOG_TAG. |
| 381 | */ |
| 382 | #ifndef SLOGD |
| 383 | #define SLOGD(...) \ |
| 384 | ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) |
| 385 | #endif |
| 386 | |
| 387 | #ifndef SLOGD_IF |
| 388 | #define SLOGD_IF(cond, ...) \ |
| 389 | ( (__predict_false(cond)) \ |
| 390 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ |
| 391 | : (void)0 ) |
| 392 | #endif |
| 393 | |
| 394 | /* |
| 395 | * Simplified macro to send an info system log message using the current LOG_TAG. |
| 396 | */ |
| 397 | #ifndef SLOGI |
| 398 | #define SLOGI(...) \ |
| 399 | ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) |
| 400 | #endif |
| 401 | |
| 402 | #ifndef SLOGI_IF |
| 403 | #define SLOGI_IF(cond, ...) \ |
| 404 | ( (__predict_false(cond)) \ |
| 405 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \ |
| 406 | : (void)0 ) |
| 407 | #endif |
| 408 | |
| 409 | /* |
| 410 | * Simplified macro to send a warning system log message using the current LOG_TAG. |
| 411 | */ |
| 412 | #ifndef SLOGW |
| 413 | #define SLOGW(...) \ |
| 414 | ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) |
| 415 | #endif |
| 416 | |
| 417 | #ifndef SLOGW_IF |
| 418 | #define SLOGW_IF(cond, ...) \ |
| 419 | ( (__predict_false(cond)) \ |
| 420 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \ |
| 421 | : (void)0 ) |
| 422 | #endif |
| 423 | |
| 424 | /* |
| 425 | * Simplified macro to send an error system log message using the current LOG_TAG. |
| 426 | */ |
| 427 | #ifndef SLOGE |
| 428 | #define SLOGE(...) \ |
| 429 | ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) |
| 430 | #endif |
| 431 | |
| 432 | #ifndef SLOGE_IF |
| 433 | #define SLOGE_IF(cond, ...) \ |
| 434 | ( (__predict_false(cond)) \ |
| 435 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ |
| 436 | : (void)0 ) |
| 437 | #endif |
| 438 | |
| 439 | #endif /* !LINT_RLOG */ |
| 440 | |
| 441 | // --------------------------------------------------------------------- |
| 442 | |
| 443 | /* |
| 444 | * Simplified macro to send a verbose radio log message using the current LOG_TAG. |
| 445 | */ |
| 446 | #ifndef RLOGV |
| 447 | #define __RLOGV(...) \ |
| 448 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) |
| 449 | #if LOG_NDEBUG |
| 450 | #define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0) |
| 451 | #else |
| 452 | #define RLOGV(...) __RLOGV(__VA_ARGS__) |
| 453 | #endif |
| 454 | #endif |
| 455 | |
| 456 | #ifndef RLOGV_IF |
| 457 | #if LOG_NDEBUG |
| 458 | #define RLOGV_IF(cond, ...) ((void)0) |
| 459 | #else |
| 460 | #define RLOGV_IF(cond, ...) \ |
| 461 | ( (__predict_false(cond)) \ |
| 462 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ |
| 463 | : (void)0 ) |
| 464 | #endif |
| 465 | #endif |
| 466 | |
| 467 | /* |
| 468 | * Simplified macro to send a debug radio log message using the current LOG_TAG. |
| 469 | */ |
| 470 | #ifndef RLOGD |
| 471 | #define RLOGD(...) \ |
| 472 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) |
| 473 | #endif |
| 474 | |
| 475 | #ifndef RLOGD_IF |
| 476 | #define RLOGD_IF(cond, ...) \ |
| 477 | ( (__predict_false(cond)) \ |
| 478 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ |
| 479 | : (void)0 ) |
| 480 | #endif |
| 481 | |
| 482 | /* |
| 483 | * Simplified macro to send an info radio log message using the current LOG_TAG. |
| 484 | */ |
| 485 | #ifndef RLOGI |
| 486 | #define RLOGI(...) \ |
| 487 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) |
| 488 | #endif |
| 489 | |
| 490 | #ifndef RLOGI_IF |
| 491 | #define RLOGI_IF(cond, ...) \ |
| 492 | ( (__predict_false(cond)) \ |
| 493 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \ |
| 494 | : (void)0 ) |
| 495 | #endif |
| 496 | |
| 497 | /* |
| 498 | * Simplified macro to send a warning radio log message using the current LOG_TAG. |
| 499 | */ |
| 500 | #ifndef RLOGW |
| 501 | #define RLOGW(...) \ |
| 502 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) |
| 503 | #endif |
| 504 | |
| 505 | #ifndef RLOGW_IF |
| 506 | #define RLOGW_IF(cond, ...) \ |
| 507 | ( (__predict_false(cond)) \ |
| 508 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \ |
| 509 | : (void)0 ) |
| 510 | #endif |
| 511 | |
| 512 | /* |
| 513 | * Simplified macro to send an error radio log message using the current LOG_TAG. |
| 514 | */ |
| 515 | #ifndef RLOGE |
| 516 | #define RLOGE(...) \ |
| 517 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) |
| 518 | #endif |
| 519 | |
| 520 | #ifndef RLOGE_IF |
| 521 | #define RLOGE_IF(cond, ...) \ |
| 522 | ( (__predict_false(cond)) \ |
| 523 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ |
| 524 | : (void)0 ) |
| 525 | #endif |
| 526 | |
| 527 | |
| 528 | // --------------------------------------------------------------------- |
| 529 | |
| 530 | /* |
| 531 | * Log a fatal error. If the given condition fails, this stops program |
| 532 | * execution like a normal assertion, but also generating the given message. |
| 533 | * It is NOT stripped from release builds. Note that the condition test |
| 534 | * is -inverted- from the normal assert() semantics. |
| 535 | */ |
| 536 | #ifndef LOG_ALWAYS_FATAL_IF |
| 537 | #define LOG_ALWAYS_FATAL_IF(cond, ...) \ |
| 538 | ( (__predict_false(cond)) \ |
| 539 | ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \ |
| 540 | : (void)0 ) |
| 541 | #endif |
| 542 | |
| 543 | #ifndef LOG_ALWAYS_FATAL |
| 544 | #define LOG_ALWAYS_FATAL(...) \ |
| 545 | ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) ) |
| 546 | #endif |
| 547 | |
| 548 | /* |
| 549 | * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that |
| 550 | * are stripped out of release builds. |
| 551 | */ |
| 552 | #if LOG_NDEBUG |
| 553 | |
| 554 | #ifndef LOG_FATAL_IF |
| 555 | #define LOG_FATAL_IF(cond, ...) ((void)0) |
| 556 | #endif |
| 557 | #ifndef LOG_FATAL |
| 558 | #define LOG_FATAL(...) ((void)0) |
| 559 | #endif |
| 560 | |
| 561 | #else |
| 562 | |
| 563 | #ifndef LOG_FATAL_IF |
| 564 | #define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__) |
| 565 | #endif |
| 566 | #ifndef LOG_FATAL |
| 567 | #define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__) |
| 568 | #endif |
| 569 | |
| 570 | #endif |
| 571 | |
| 572 | /* |
| 573 | * Assertion that generates a log message when the assertion fails. |
| 574 | * Stripped out of release builds. Uses the current LOG_TAG. |
| 575 | */ |
| 576 | #ifndef ALOG_ASSERT |
| 577 | #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__) |
| 578 | //#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond) |
| 579 | #endif |
| 580 | |
| 581 | // --------------------------------------------------------------------- |
| 582 | |
| 583 | /* |
| 584 | * Basic log message macro. |
| 585 | * |
| 586 | * Example: |
| 587 | * ALOG(LOG_WARN, NULL, "Failed with error %d", errno); |
| 588 | * |
| 589 | * The second argument may be NULL or "" to indicate the "global" tag. |
| 590 | */ |
| 591 | #ifndef ALOG |
| 592 | #define ALOG(priority, tag, ...) \ |
| 593 | LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) |
| 594 | #endif |
| 595 | |
| 596 | /* |
| 597 | * Log macro that allows you to specify a number for the priority. |
| 598 | */ |
| 599 | #ifndef LOG_PRI |
| 600 | #define LOG_PRI(priority, tag, ...) \ |
| 601 | android_printLog(priority, tag, __VA_ARGS__) |
| 602 | #endif |
| 603 | |
| 604 | /* |
| 605 | * Log macro that allows you to pass in a varargs ("args" is a va_list). |
| 606 | */ |
| 607 | #ifndef LOG_PRI_VA |
| 608 | #define LOG_PRI_VA(priority, tag, fmt, args) \ |
| 609 | android_vprintLog(priority, NULL, tag, fmt, args) |
| 610 | #endif |
| 611 | |
| 612 | /* |
| 613 | * Conditional given a desired logging priority and tag. |
| 614 | */ |
| 615 | #ifndef IF_ALOG |
| 616 | #define IF_ALOG(priority, tag) \ |
| 617 | if (android_testLog(ANDROID_##priority, tag)) |
| 618 | #endif |
| 619 | |
| 620 | // --------------------------------------------------------------------- |
| 621 | |
| 622 | /* |
| 623 | * Event logging. |
| 624 | */ |
| 625 | |
| 626 | /* |
| 627 | * Event log entry types. |
| 628 | */ |
| 629 | typedef enum { |
| 630 | /* Special markers for android_log_list_element type */ |
| 631 | EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */ |
| 632 | EVENT_TYPE_UNKNOWN = '?', /* protocol error */ |
| 633 | |
| 634 | /* must match with declaration in java/android/android/util/EventLog.java */ |
| 635 | EVENT_TYPE_INT = 0, /* uint32_t */ |
| 636 | EVENT_TYPE_LONG = 1, /* uint64_t */ |
| 637 | EVENT_TYPE_STRING = 2, |
| 638 | EVENT_TYPE_LIST = 3, |
| 639 | EVENT_TYPE_FLOAT = 4, |
| 640 | } AndroidEventLogType; |
| 641 | #define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType) |
| 642 | #define typeof_AndroidEventLogType unsigned char |
| 643 | |
| 644 | #ifndef LOG_EVENT_INT |
| 645 | #define LOG_EVENT_INT(_tag, _value) { \ |
| 646 | int intBuf = _value; \ |
| 647 | (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \ |
| 648 | sizeof(intBuf)); \ |
| 649 | } |
| 650 | #endif |
| 651 | #ifndef LOG_EVENT_LONG |
| 652 | #define LOG_EVENT_LONG(_tag, _value) { \ |
| 653 | long long longBuf = _value; \ |
| 654 | (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \ |
| 655 | sizeof(longBuf)); \ |
| 656 | } |
| 657 | #endif |
| 658 | #ifndef LOG_EVENT_FLOAT |
| 659 | #define LOG_EVENT_FLOAT(_tag, _value) { \ |
| 660 | float floatBuf = _value; \ |
| 661 | (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \ |
| 662 | sizeof(floatBuf)); \ |
| 663 | } |
| 664 | #endif |
| 665 | #ifndef LOG_EVENT_STRING |
| 666 | #define LOG_EVENT_STRING(_tag, _value) \ |
| 667 | (void) __android_log_bswrite(_tag, _value); |
| 668 | #endif |
| 669 | |
| 670 | typedef enum log_id { |
| 671 | LOG_ID_MIN = 0, |
| 672 | |
| 673 | #ifndef LINT_RLOG |
| 674 | LOG_ID_MAIN = 0, |
| 675 | #endif |
| 676 | LOG_ID_RADIO = 1, |
| 677 | #ifndef LINT_RLOG |
| 678 | LOG_ID_EVENTS = 2, |
| 679 | LOG_ID_SYSTEM = 3, |
| 680 | LOG_ID_CRASH = 4, |
| 681 | LOG_ID_SECURITY = 5, |
| 682 | LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */ |
| 683 | #endif |
| 684 | |
| 685 | LOG_ID_MAX |
| 686 | } log_id_t; |
| 687 | #define sizeof_log_id_t sizeof(typeof_log_id_t) |
| 688 | #define typeof_log_id_t unsigned char |
| 689 | |
| 690 | /* For manipulating lists of events. */ |
| 691 | |
| 692 | #define ANDROID_MAX_LIST_NEST_DEPTH 8 |
| 693 | |
| 694 | /* |
| 695 | * The opaque context used to manipulate lists of events. |
| 696 | */ |
| 697 | typedef struct android_log_context_internal *android_log_context; |
| 698 | |
| 699 | /* |
| 700 | * Elements returned when reading a list of events. |
| 701 | */ |
| 702 | typedef struct { |
| 703 | AndroidEventLogType type; |
| 704 | uint16_t complete; |
| 705 | uint16_t len; |
| 706 | union { |
| 707 | int32_t int32; |
| 708 | int64_t int64; |
| 709 | char *string; |
| 710 | float float32; |
| 711 | } data; |
| 712 | } android_log_list_element; |
| 713 | |
| 714 | /* |
| 715 | * Creates a context associated with an event tag to write elements to |
| 716 | * the list of events. |
| 717 | */ |
| 718 | android_log_context create_android_logger(uint32_t tag); |
| 719 | |
| 720 | /* All lists must be braced by a begin and end call */ |
| 721 | /* |
| 722 | * NB: If the first level braces are missing when specifying multiple |
| 723 | * elements, we will manufacturer a list to embrace it for your API |
| 724 | * convenience. For a single element, it will remain solitary. |
| 725 | */ |
| 726 | int android_log_write_list_begin(android_log_context ctx); |
| 727 | int android_log_write_list_end(android_log_context ctx); |
| 728 | |
| 729 | int android_log_write_int32(android_log_context ctx, int32_t value); |
| 730 | int android_log_write_int64(android_log_context ctx, int64_t value); |
| 731 | int android_log_write_string8(android_log_context ctx, const char *value); |
| 732 | int android_log_write_string8_len(android_log_context ctx, |
| 733 | const char *value, size_t maxlen); |
| 734 | int android_log_write_float32(android_log_context ctx, float value); |
| 735 | |
| 736 | /* Submit the composed list context to the specified logger id */ |
| 737 | /* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */ |
| 738 | int android_log_write_list(android_log_context ctx, log_id_t id); |
| 739 | |
| 740 | /* |
| 741 | * Creates a context from a raw buffer representing a list of events to be read. |
| 742 | */ |
| 743 | android_log_context create_android_log_parser(const char *msg, size_t len); |
| 744 | |
| 745 | android_log_list_element android_log_read_next(android_log_context ctx); |
| 746 | android_log_list_element android_log_peek_next(android_log_context ctx); |
| 747 | |
| 748 | /* Finished with reader or writer context */ |
| 749 | int android_log_destroy(android_log_context *ctx); |
| 750 | |
| 751 | /* |
| 752 | * =========================================================================== |
| 753 | * |
| 754 | * The stuff in the rest of this file should not be used directly. |
| 755 | */ |
| 756 | |
| 757 | #define android_printLog(prio, tag, ...) \ |
| 758 | __android_log_print(prio, tag, __VA_ARGS__) |
| 759 | |
| 760 | #define android_vprintLog(prio, cond, tag, ...) \ |
| 761 | __android_log_vprint(prio, tag, __VA_ARGS__) |
| 762 | |
| 763 | /* XXX Macros to work around syntax errors in places where format string |
| 764 | * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF |
| 765 | * (happens only in debug builds). |
| 766 | */ |
| 767 | |
| 768 | /* Returns 2nd arg. Used to substitute default value if caller's vararg list |
| 769 | * is empty. |
| 770 | */ |
| 771 | #define __android_second(dummy, second, ...) second |
| 772 | |
| 773 | /* If passed multiple args, returns ',' followed by all but 1st arg, otherwise |
| 774 | * returns nothing. |
| 775 | */ |
| 776 | #define __android_rest(first, ...) , ## __VA_ARGS__ |
| 777 | |
| 778 | #define android_printAssert(cond, tag, ...) \ |
| 779 | __android_log_assert(cond, tag, \ |
| 780 | __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__)) |
| 781 | |
| 782 | #define android_writeLog(prio, tag, text) \ |
| 783 | __android_log_write(prio, tag, text) |
| 784 | |
| 785 | #define android_bWriteLog(tag, payload, len) \ |
| 786 | __android_log_bwrite(tag, payload, len) |
| 787 | #define android_btWriteLog(tag, type, payload, len) \ |
| 788 | __android_log_btwrite(tag, type, payload, len) |
| 789 | |
| 790 | #define android_errorWriteLog(tag, subTag) \ |
| 791 | __android_log_error_write(tag, subTag, -1, NULL, 0) |
| 792 | |
| 793 | #define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \ |
| 794 | __android_log_error_write(tag, subTag, uid, data, dataLen) |
| 795 | |
| 796 | /* |
| 797 | * IF_ALOG uses android_testLog, but IF_ALOG can be overridden. |
| 798 | * android_testLog will remain constant in its purpose as a wrapper |
| 799 | * for Android logging filter policy, and can be subject to |
| 800 | * change. It can be reused by the developers that override |
| 801 | * IF_ALOG as a convenient means to reimplement their policy |
| 802 | * over Android. |
| 803 | */ |
| 804 | #if LOG_NDEBUG /* Production */ |
| 805 | #define android_testLog(prio, tag) \ |
Mark Salyzyn | 807e40e | 2016-09-22 09:56:51 -0700 | [diff] [blame^] | 806 | (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ |
| 807 | ANDROID_LOG_DEBUG) != 0) |
Mark Salyzyn | 6584d0a | 2016-09-28 13:26:55 -0700 | [diff] [blame] | 808 | #else |
| 809 | #define android_testLog(prio, tag) \ |
Mark Salyzyn | 807e40e | 2016-09-22 09:56:51 -0700 | [diff] [blame^] | 810 | (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ |
| 811 | ANDROID_LOG_VERBOSE) != 0) |
Mark Salyzyn | 6584d0a | 2016-09-28 13:26:55 -0700 | [diff] [blame] | 812 | #endif |
| 813 | |
| 814 | /* |
| 815 | * Use the per-tag properties "log.tag.<tagname>" to generate a runtime |
| 816 | * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to |
| 817 | * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if |
| 818 | * any other value. |
| 819 | */ |
| 820 | int __android_log_is_loggable(int prio, const char *tag, int default_prio); |
Mark Salyzyn | 807e40e | 2016-09-22 09:56:51 -0700 | [diff] [blame^] | 821 | int __android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio); |
Mark Salyzyn | 6584d0a | 2016-09-28 13:26:55 -0700 | [diff] [blame] | 822 | |
| 823 | int __android_log_security(); /* Device Owner is present */ |
| 824 | |
| 825 | int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data, |
| 826 | uint32_t dataLen); |
| 827 | |
| 828 | /* |
| 829 | * Send a simple string to the log. |
| 830 | */ |
| 831 | int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text); |
| 832 | int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...) |
| 833 | #if defined(__GNUC__) |
| 834 | __attribute__((__format__(printf, 4, 5))) |
| 835 | #endif |
| 836 | ; |
| 837 | |
| 838 | #if defined(__clang__) |
| 839 | #pragma clang diagnostic pop |
| 840 | #endif |
| 841 | |
David 'Digit' Turner | ebefc48 | 2009-05-29 14:45:04 +0200 | [diff] [blame] | 842 | #ifdef __cplusplus |
| 843 | } |
| 844 | #endif |
| 845 | |
| 846 | #endif /* _ANDROID_LOG_H */ |