Home | History | Annotate | Download | only in log
      1 /*
      2  * Copyright (C) 2005-2014 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 //
     18 // C/C++ logging functions.  See the logging documentation for API details.
     19 //
     20 // We'd like these to be available from C code (in case we import some from
     21 // somewhere), so this has a C interface.
     22 //
     23 // The output will be correct when the log file is shared between multiple
     24 // threads and/or multiple processes so long as the operating system
     25 // supports O_APPEND.  These calls have mutex-protected data structures
     26 // and so are NOT reentrant.  Do not use LOG in a signal handler.
     27 //
     28 #ifndef _LIBS_LOG_LOG_H
     29 #define _LIBS_LOG_LOG_H
     30 
     31 #include <stdarg.h>
     32 #include <stdio.h>
     33 #include <sys/types.h>
     34 #include <time.h>
     35 #include <unistd.h>
     36 
     37 #include <log/logd.h>
     38 #include <log/uio.h>
     39 
     40 #ifdef __cplusplus
     41 extern "C" {
     42 #endif
     43 
     44 // ---------------------------------------------------------------------
     45 
     46 /*
     47  * Normally we strip ALOGV (VERBOSE messages) from release builds.
     48  * You can modify this (for example with "#define LOG_NDEBUG 0"
     49  * at the top of your source file) to change that behavior.
     50  */
     51 #ifndef LOG_NDEBUG
     52 #ifdef NDEBUG
     53 #define LOG_NDEBUG 1
     54 #else
     55 #define LOG_NDEBUG 0
     56 #endif
     57 #endif
     58 
     59 /*
     60  * This is the local tag used for the following simplified
     61  * logging macros.  You can change this preprocessor definition
     62  * before using the other macros to change the tag.
     63  */
     64 #ifndef LOG_TAG
     65 #define LOG_TAG NULL
     66 #endif
     67 
     68 // ---------------------------------------------------------------------
     69 
     70 #ifndef __predict_false
     71 #define __predict_false(exp) __builtin_expect((exp) != 0, 0)
     72 #endif
     73 
     74 /*
     75  *      -DLINT_RLOG in sources that you want to enforce that all logging
     76  * goes to the radio log buffer. If any logging goes to any of the other
     77  * log buffers, there will be a compile or link error to highlight the
     78  * problem. This is not a replacement for a full audit of the code since
     79  * this only catches compiled code, not ifdef'd debug code. Options to
     80  * defining this, either temporarily to do a spot check, or permanently
     81  * to enforce, in all the communications trees; We have hopes to ensure
     82  * that by supplying just the radio log buffer that the communications
     83  * teams will have their one-stop shop for triaging issues.
     84  */
     85 #ifndef LINT_RLOG
     86 
     87 /*
     88  * Simplified macro to send a verbose log message using the current LOG_TAG.
     89  */
     90 #ifndef ALOGV
     91 #define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
     92 #if LOG_NDEBUG
     93 #define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
     94 #else
     95 #define ALOGV(...) __ALOGV(__VA_ARGS__)
     96 #endif
     97 #endif
     98 
     99 #ifndef ALOGV_IF
    100 #if LOG_NDEBUG
    101 #define ALOGV_IF(cond, ...)   ((void)0)
    102 #else
    103 #define ALOGV_IF(cond, ...) \
    104     ( (__predict_false(cond)) \
    105     ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
    106     : (void)0 )
    107 #endif
    108 #endif
    109 
    110 /*
    111  * Simplified macro to send a debug log message using the current LOG_TAG.
    112  */
    113 #ifndef ALOGD
    114 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
    115 #endif
    116 
    117 #ifndef ALOGD_IF
    118 #define ALOGD_IF(cond, ...) \
    119     ( (__predict_false(cond)) \
    120     ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
    121     : (void)0 )
    122 #endif
    123 
    124 /*
    125  * Simplified macro to send an info log message using the current LOG_TAG.
    126  */
    127 #ifndef ALOGI
    128 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
    129 #endif
    130 
    131 #ifndef ALOGI_IF
    132 #define ALOGI_IF(cond, ...) \
    133     ( (__predict_false(cond)) \
    134     ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
    135     : (void)0 )
    136 #endif
    137 
    138 /*
    139  * Simplified macro to send a warning log message using the current LOG_TAG.
    140  */
    141 #ifndef ALOGW
    142 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
    143 #endif
    144 
    145 #ifndef ALOGW_IF
    146 #define ALOGW_IF(cond, ...) \
    147     ( (__predict_false(cond)) \
    148     ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
    149     : (void)0 )
    150 #endif
    151 
    152 /*
    153  * Simplified macro to send an error log message using the current LOG_TAG.
    154  */
    155 #ifndef ALOGE
    156 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
    157 #endif
    158 
    159 #ifndef ALOGE_IF
    160 #define ALOGE_IF(cond, ...) \
    161     ( (__predict_false(cond)) \
    162     ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
    163     : (void)0 )
    164 #endif
    165 
    166 // ---------------------------------------------------------------------
    167 
    168 /*
    169  * Conditional based on whether the current LOG_TAG is enabled at
    170  * verbose priority.
    171  */
    172 #ifndef IF_ALOGV
    173 #if LOG_NDEBUG
    174 #define IF_ALOGV() if (false)
    175 #else
    176 #define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
    177 #endif
    178 #endif
    179 
    180 /*
    181  * Conditional based on whether the current LOG_TAG is enabled at
    182  * debug priority.
    183  */
    184 #ifndef IF_ALOGD
    185 #define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
    186 #endif
    187 
    188 /*
    189  * Conditional based on whether the current LOG_TAG is enabled at
    190  * info priority.
    191  */
    192 #ifndef IF_ALOGI
    193 #define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
    194 #endif
    195 
    196 /*
    197  * Conditional based on whether the current LOG_TAG is enabled at
    198  * warn priority.
    199  */
    200 #ifndef IF_ALOGW
    201 #define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
    202 #endif
    203 
    204 /*
    205  * Conditional based on whether the current LOG_TAG is enabled at
    206  * error priority.
    207  */
    208 #ifndef IF_ALOGE
    209 #define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
    210 #endif
    211 
    212 
    213 // ---------------------------------------------------------------------
    214 
    215 /*
    216  * Simplified macro to send a verbose system log message using the current LOG_TAG.
    217  */
    218 #ifndef SLOGV
    219 #define __SLOGV(...) \
    220     ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
    221 #if LOG_NDEBUG
    222 #define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
    223 #else
    224 #define SLOGV(...) __SLOGV(__VA_ARGS__)
    225 #endif
    226 #endif
    227 
    228 #ifndef SLOGV_IF
    229 #if LOG_NDEBUG
    230 #define SLOGV_IF(cond, ...)   ((void)0)
    231 #else
    232 #define SLOGV_IF(cond, ...) \
    233     ( (__predict_false(cond)) \
    234     ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
    235     : (void)0 )
    236 #endif
    237 #endif
    238 
    239 /*
    240  * Simplified macro to send a debug system log message using the current LOG_TAG.
    241  */
    242 #ifndef SLOGD
    243 #define SLOGD(...) \
    244     ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
    245 #endif
    246 
    247 #ifndef SLOGD_IF
    248 #define SLOGD_IF(cond, ...) \
    249     ( (__predict_false(cond)) \
    250     ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
    251     : (void)0 )
    252 #endif
    253 
    254 /*
    255  * Simplified macro to send an info system log message using the current LOG_TAG.
    256  */
    257 #ifndef SLOGI
    258 #define SLOGI(...) \
    259     ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
    260 #endif
    261 
    262 #ifndef SLOGI_IF
    263 #define SLOGI_IF(cond, ...) \
    264     ( (__predict_false(cond)) \
    265     ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
    266     : (void)0 )
    267 #endif
    268 
    269 /*
    270  * Simplified macro to send a warning system log message using the current LOG_TAG.
    271  */
    272 #ifndef SLOGW
    273 #define SLOGW(...) \
    274     ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
    275 #endif
    276 
    277 #ifndef SLOGW_IF
    278 #define SLOGW_IF(cond, ...) \
    279     ( (__predict_false(cond)) \
    280     ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
    281     : (void)0 )
    282 #endif
    283 
    284 /*
    285  * Simplified macro to send an error system log message using the current LOG_TAG.
    286  */
    287 #ifndef SLOGE
    288 #define SLOGE(...) \
    289     ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
    290 #endif
    291 
    292 #ifndef SLOGE_IF
    293 #define SLOGE_IF(cond, ...) \
    294     ( (__predict_false(cond)) \
    295     ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
    296     : (void)0 )
    297 #endif
    298 
    299 #endif /* !LINT_RLOG */
    300 
    301 // ---------------------------------------------------------------------
    302 
    303 /*
    304  * Simplified macro to send a verbose radio log message using the current LOG_TAG.
    305  */
    306 #ifndef RLOGV
    307 #define __RLOGV(...) \
    308     ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
    309 #if LOG_NDEBUG
    310 #define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
    311 #else
    312 #define RLOGV(...) __RLOGV(__VA_ARGS__)
    313 #endif
    314 #endif
    315 
    316 #ifndef RLOGV_IF
    317 #if LOG_NDEBUG
    318 #define RLOGV_IF(cond, ...)   ((void)0)
    319 #else
    320 #define RLOGV_IF(cond, ...) \
    321     ( (__predict_false(cond)) \
    322     ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
    323     : (void)0 )
    324 #endif
    325 #endif
    326 
    327 /*
    328  * Simplified macro to send a debug radio log message using the current LOG_TAG.
    329  */
    330 #ifndef RLOGD
    331 #define RLOGD(...) \
    332     ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
    333 #endif
    334 
    335 #ifndef RLOGD_IF
    336 #define RLOGD_IF(cond, ...) \
    337     ( (__predict_false(cond)) \
    338     ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
    339     : (void)0 )
    340 #endif
    341 
    342 /*
    343  * Simplified macro to send an info radio log message using the current LOG_TAG.
    344  */
    345 #ifndef RLOGI
    346 #define RLOGI(...) \
    347     ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
    348 #endif
    349 
    350 #ifndef RLOGI_IF
    351 #define RLOGI_IF(cond, ...) \
    352     ( (__predict_false(cond)) \
    353     ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
    354     : (void)0 )
    355 #endif
    356 
    357 /*
    358  * Simplified macro to send a warning radio log message using the current LOG_TAG.
    359  */
    360 #ifndef RLOGW
    361 #define RLOGW(...) \
    362     ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
    363 #endif
    364 
    365 #ifndef RLOGW_IF
    366 #define RLOGW_IF(cond, ...) \
    367     ( (__predict_false(cond)) \
    368     ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
    369     : (void)0 )
    370 #endif
    371 
    372 /*
    373  * Simplified macro to send an error radio log message using the current LOG_TAG.
    374  */
    375 #ifndef RLOGE
    376 #define RLOGE(...) \
    377     ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
    378 #endif
    379 
    380 #ifndef RLOGE_IF
    381 #define RLOGE_IF(cond, ...) \
    382     ( (__predict_false(cond)) \
    383     ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
    384     : (void)0 )
    385 #endif
    386 
    387 
    388 // ---------------------------------------------------------------------
    389 
    390 /*
    391  * Log a fatal error.  If the given condition fails, this stops program
    392  * execution like a normal assertion, but also generating the given message.
    393  * It is NOT stripped from release builds.  Note that the condition test
    394  * is -inverted- from the normal assert() semantics.
    395  */
    396 #ifndef LOG_ALWAYS_FATAL_IF
    397 #define LOG_ALWAYS_FATAL_IF(cond, ...) \
    398     ( (__predict_false(cond)) \
    399     ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
    400     : (void)0 )
    401 #endif
    402 
    403 #ifndef LOG_ALWAYS_FATAL
    404 #define LOG_ALWAYS_FATAL(...) \
    405     ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
    406 #endif
    407 
    408 /*
    409  * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
    410  * are stripped out of release builds.
    411  */
    412 #if LOG_NDEBUG
    413 
    414 #ifndef LOG_FATAL_IF
    415 #define LOG_FATAL_IF(cond, ...) ((void)0)
    416 #endif
    417 #ifndef LOG_FATAL
    418 #define LOG_FATAL(...) ((void)0)
    419 #endif
    420 
    421 #else
    422 
    423 #ifndef LOG_FATAL_IF
    424 #define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
    425 #endif
    426 #ifndef LOG_FATAL
    427 #define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
    428 #endif
    429 
    430 #endif
    431 
    432 /*
    433  * Assertion that generates a log message when the assertion fails.
    434  * Stripped out of release builds.  Uses the current LOG_TAG.
    435  */
    436 #ifndef ALOG_ASSERT
    437 #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
    438 //#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
    439 #endif
    440 
    441 // ---------------------------------------------------------------------
    442 
    443 /*
    444  * Basic log message macro.
    445  *
    446  * Example:
    447  *  ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
    448  *
    449  * The second argument may be NULL or "" to indicate the "global" tag.
    450  */
    451 #ifndef ALOG
    452 #define ALOG(priority, tag, ...) \
    453     LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
    454 #endif
    455 
    456 /*
    457  * Log macro that allows you to specify a number for the priority.
    458  */
    459 #ifndef LOG_PRI
    460 #define LOG_PRI(priority, tag, ...) \
    461     android_printLog(priority, tag, __VA_ARGS__)
    462 #endif
    463 
    464 /*
    465  * Log macro that allows you to pass in a varargs ("args" is a va_list).
    466  */
    467 #ifndef LOG_PRI_VA
    468 #define LOG_PRI_VA(priority, tag, fmt, args) \
    469     android_vprintLog(priority, NULL, tag, fmt, args)
    470 #endif
    471 
    472 /*
    473  * Conditional given a desired logging priority and tag.
    474  */
    475 #ifndef IF_ALOG
    476 #define IF_ALOG(priority, tag) \
    477     if (android_testLog(ANDROID_##priority, tag))
    478 #endif
    479 
    480 // ---------------------------------------------------------------------
    481 
    482 /*
    483  * Event logging.
    484  */
    485 
    486 /*
    487  * Event log entry types.
    488  */
    489 typedef enum {
    490     /* Special markers for android_log_list_element type */
    491     EVENT_TYPE_LIST_STOP = '\n', /* declare end of list  */
    492     EVENT_TYPE_UNKNOWN   = '?',  /* protocol error       */
    493 
    494     /* must match with declaration in java/android/android/util/EventLog.java */
    495     EVENT_TYPE_INT       = 0,    /* uint32_t */
    496     EVENT_TYPE_LONG      = 1,    /* uint64_t */
    497     EVENT_TYPE_STRING    = 2,
    498     EVENT_TYPE_LIST      = 3,
    499     EVENT_TYPE_FLOAT     = 4,
    500 } AndroidEventLogType;
    501 #define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
    502 #define typeof_AndroidEventLogType unsigned char
    503 
    504 #ifndef LOG_EVENT_INT
    505 #define LOG_EVENT_INT(_tag, _value) {                                       \
    506         int intBuf = _value;                                                \
    507         (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf,            \
    508             sizeof(intBuf));                                                \
    509     }
    510 #endif
    511 #ifndef LOG_EVENT_LONG
    512 #define LOG_EVENT_LONG(_tag, _value) {                                      \
    513         long long longBuf = _value;                                         \
    514         (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf,          \
    515             sizeof(longBuf));                                               \
    516     }
    517 #endif
    518 #ifndef LOG_EVENT_FLOAT
    519 #define LOG_EVENT_FLOAT(_tag, _value) {                                     \
    520         float floatBuf = _value;                                            \
    521         (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf,        \
    522             sizeof(floatBuf));                                              \
    523     }
    524 #endif
    525 #ifndef LOG_EVENT_STRING
    526 #define LOG_EVENT_STRING(_tag, _value)                                      \
    527         (void) __android_log_bswrite(_tag, _value);
    528 #endif
    529 
    530 typedef enum log_id {
    531     LOG_ID_MIN = 0,
    532 
    533 #ifndef LINT_RLOG
    534     LOG_ID_MAIN = 0,
    535 #endif
    536     LOG_ID_RADIO = 1,
    537 #ifndef LINT_RLOG
    538     LOG_ID_EVENTS = 2,
    539     LOG_ID_SYSTEM = 3,
    540     LOG_ID_CRASH = 4,
    541     LOG_ID_SECURITY = 5,
    542     LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
    543 #endif
    544 
    545     LOG_ID_MAX
    546 } log_id_t;
    547 #define sizeof_log_id_t sizeof(typeof_log_id_t)
    548 #define typeof_log_id_t unsigned char
    549 
    550 /* For manipulating lists of events. */
    551 
    552 #define ANDROID_MAX_LIST_NEST_DEPTH 8
    553 
    554 /*
    555  * The opaque context used to manipulate lists of events.
    556  */
    557 typedef struct android_log_context_internal *android_log_context;
    558 
    559 /*
    560  * Elements returned when reading a list of events.
    561  */
    562 typedef struct {
    563     AndroidEventLogType type;
    564     uint16_t complete;
    565     uint16_t len;
    566     union {
    567         int32_t int32;
    568         int64_t int64;
    569         char *string;
    570         float float32;
    571     } data;
    572 } android_log_list_element;
    573 
    574 /*
    575  * Creates a context associated with an event tag to write elements to
    576  * the list of events.
    577  */
    578 android_log_context create_android_logger(uint32_t tag);
    579 
    580 /* All lists must be braced by a begin and end call */
    581 /*
    582  * NB: If the first level braces are missing when specifying multiple
    583  *     elements, we will manufacturer a list to embrace it for your API
    584  *     convenience. For a single element, it will remain solitary.
    585  */
    586 int android_log_write_list_begin(android_log_context ctx);
    587 int android_log_write_list_end(android_log_context ctx);
    588 
    589 int android_log_write_int32(android_log_context ctx, int32_t value);
    590 int android_log_write_int64(android_log_context ctx, int64_t value);
    591 int android_log_write_string8(android_log_context ctx, const char *value);
    592 int android_log_write_string8_len(android_log_context ctx,
    593                                   const char *value, size_t maxlen);
    594 int android_log_write_float32(android_log_context ctx, float value);
    595 
    596 /* Submit the composed list context to the specified logger id */
    597 /* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
    598 int android_log_write_list(android_log_context ctx, log_id_t id);
    599 
    600 /*
    601  * Creates a context from a raw buffer representing a list of events to be read.
    602  */
    603 android_log_context create_android_log_parser(const char *msg, size_t len);
    604 
    605 android_log_list_element android_log_read_next(android_log_context ctx);
    606 android_log_list_element android_log_peek_next(android_log_context ctx);
    607 
    608 /* Finished with reader or writer context */
    609 int android_log_destroy(android_log_context *ctx);
    610 
    611 /*
    612  * ===========================================================================
    613  *
    614  * The stuff in the rest of this file should not be used directly.
    615  */
    616 
    617 #define android_printLog(prio, tag, fmt...) \
    618     __android_log_print(prio, tag, fmt)
    619 
    620 #define android_vprintLog(prio, cond, tag, fmt...) \
    621     __android_log_vprint(prio, tag, fmt)
    622 
    623 /* XXX Macros to work around syntax errors in places where format string
    624  * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
    625  * (happens only in debug builds).
    626  */
    627 
    628 /* Returns 2nd arg.  Used to substitute default value if caller's vararg list
    629  * is empty.
    630  */
    631 #define __android_second(dummy, second, ...)     second
    632 
    633 /* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
    634  * returns nothing.
    635  */
    636 #define __android_rest(first, ...)               , ## __VA_ARGS__
    637 
    638 #define android_printAssert(cond, tag, fmt...) \
    639     __android_log_assert(cond, tag, \
    640         __android_second(0, ## fmt, NULL) __android_rest(fmt))
    641 
    642 #define android_writeLog(prio, tag, text) \
    643     __android_log_write(prio, tag, text)
    644 
    645 #define android_bWriteLog(tag, payload, len) \
    646     __android_log_bwrite(tag, payload, len)
    647 #define android_btWriteLog(tag, type, payload, len) \
    648     __android_log_btwrite(tag, type, payload, len)
    649 
    650 #define android_errorWriteLog(tag, subTag) \
    651     __android_log_error_write(tag, subTag, -1, NULL, 0)
    652 
    653 #define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
    654     __android_log_error_write(tag, subTag, uid, data, dataLen)
    655 
    656 /*
    657  *    IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
    658  *    android_testLog will remain constant in its purpose as a wrapper
    659  *        for Android logging filter policy, and can be subject to
    660  *        change. It can be reused by the developers that override
    661  *        IF_ALOG as a convenient means to reimplement their policy
    662  *        over Android.
    663  */
    664 #if LOG_NDEBUG /* Production */
    665 #define android_testLog(prio, tag) \
    666     (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
    667 #else
    668 #define android_testLog(prio, tag) \
    669     (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
    670 #endif
    671 
    672 /*
    673  * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
    674  * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
    675  * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
    676  * any other value.
    677  */
    678 int __android_log_is_loggable(int prio, const char *tag, int default_prio);
    679 
    680 int __android_log_security(); /* Device Owner is present */
    681 
    682 int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
    683                               uint32_t dataLen);
    684 
    685 /*
    686  * Send a simple string to the log.
    687  */
    688 int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
    689 int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
    690 #if defined(__GNUC__)
    691     __attribute__((__format__(printf, 4, 5)))
    692 #endif
    693     ;
    694 
    695 #ifdef __cplusplus
    696 }
    697 #endif
    698 
    699 #endif /* _LIBS_LOG_LOG_H */
    700