media/omx-plugin/include/ics/cutils/log.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * Copyright (C) 2005 The Android Open Source Project
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 //
michael@0 18 // C/C++ logging functions. See the logging documentation for API details.
michael@0 19 //
michael@0 20 // We'd like these to be available from C code (in case we import some from
michael@0 21 // somewhere), so this has a C interface.
michael@0 22 //
michael@0 23 // The output will be correct when the log file is shared between multiple
michael@0 24 // threads and/or multiple processes so long as the operating system
michael@0 25 // supports O_APPEND. These calls have mutex-protected data structures
michael@0 26 // and so are NOT reentrant. Do not use LOG in a signal handler.
michael@0 27 //
michael@0 28 #ifndef _LIBS_CUTILS_LOG_H
michael@0 29 #define _LIBS_CUTILS_LOG_H
michael@0 30
michael@0 31 #include <stdio.h>
michael@0 32 #include <time.h>
michael@0 33 #include <sys/types.h>
michael@0 34 #include <unistd.h>
michael@0 35 #ifdef HAVE_PTHREADS
michael@0 36 #include <pthread.h>
michael@0 37 #endif
michael@0 38 #include <stdarg.h>
michael@0 39
michael@0 40 #include <cutils/uio.h>
michael@0 41 #include <cutils/logd.h>
michael@0 42
michael@0 43 #ifdef __cplusplus
michael@0 44 extern "C" {
michael@0 45 #endif
michael@0 46
michael@0 47 // ---------------------------------------------------------------------
michael@0 48
michael@0 49 /*
michael@0 50 * Normally we strip LOGV (VERBOSE messages) from release builds.
michael@0 51 * You can modify this (for example with "#define LOG_NDEBUG 0"
michael@0 52 * at the top of your source file) to change that behavior.
michael@0 53 */
michael@0 54 #ifndef LOG_NDEBUG
michael@0 55 #ifdef NDEBUG
michael@0 56 #define LOG_NDEBUG 1
michael@0 57 #else
michael@0 58 #define LOG_NDEBUG 0
michael@0 59 #endif
michael@0 60 #endif
michael@0 61
michael@0 62 /*
michael@0 63 * This is the local tag used for the following simplified
michael@0 64 * logging macros. You can change this preprocessor definition
michael@0 65 * before using the other macros to change the tag.
michael@0 66 */
michael@0 67 #ifndef LOG_TAG
michael@0 68 #define LOG_TAG NULL
michael@0 69 #endif
michael@0 70
michael@0 71 // ---------------------------------------------------------------------
michael@0 72
michael@0 73 /*
michael@0 74 * Simplified macro to send a verbose log message using the current LOG_TAG.
michael@0 75 */
michael@0 76 #ifndef LOGV
michael@0 77 #if LOG_NDEBUG
michael@0 78 #define LOGV(...) ((void)0)
michael@0 79 #else
michael@0 80 #define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
michael@0 81 #endif
michael@0 82 #endif
michael@0 83
michael@0 84 #define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
michael@0 85
michael@0 86 #ifndef LOGV_IF
michael@0 87 #if LOG_NDEBUG
michael@0 88 #define LOGV_IF(cond, ...) ((void)0)
michael@0 89 #else
michael@0 90 #define LOGV_IF(cond, ...) \
michael@0 91 ( (CONDITION(cond)) \
michael@0 92 ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
michael@0 93 : (void)0 )
michael@0 94 #endif
michael@0 95 #endif
michael@0 96
michael@0 97 /*
michael@0 98 * Simplified macro to send a debug log message using the current LOG_TAG.
michael@0 99 */
michael@0 100 #ifndef LOGD
michael@0 101 #define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
michael@0 102 #endif
michael@0 103
michael@0 104 #ifndef LOGD_IF
michael@0 105 #define LOGD_IF(cond, ...) \
michael@0 106 ( (CONDITION(cond)) \
michael@0 107 ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
michael@0 108 : (void)0 )
michael@0 109 #endif
michael@0 110
michael@0 111 /*
michael@0 112 * Simplified macro to send an info log message using the current LOG_TAG.
michael@0 113 */
michael@0 114 #ifndef LOGI
michael@0 115 #define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
michael@0 116 #endif
michael@0 117
michael@0 118 #ifndef LOGI_IF
michael@0 119 #define LOGI_IF(cond, ...) \
michael@0 120 ( (CONDITION(cond)) \
michael@0 121 ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
michael@0 122 : (void)0 )
michael@0 123 #endif
michael@0 124
michael@0 125 /*
michael@0 126 * Simplified macro to send a warning log message using the current LOG_TAG.
michael@0 127 */
michael@0 128 #ifndef LOGW
michael@0 129 #define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
michael@0 130 #endif
michael@0 131
michael@0 132 #ifndef LOGW_IF
michael@0 133 #define LOGW_IF(cond, ...) \
michael@0 134 ( (CONDITION(cond)) \
michael@0 135 ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
michael@0 136 : (void)0 )
michael@0 137 #endif
michael@0 138
michael@0 139 /*
michael@0 140 * Simplified macro to send an error log message using the current LOG_TAG.
michael@0 141 */
michael@0 142 #ifndef LOGE
michael@0 143 #define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
michael@0 144 #endif
michael@0 145
michael@0 146 #ifndef LOGE_IF
michael@0 147 #define LOGE_IF(cond, ...) \
michael@0 148 ( (CONDITION(cond)) \
michael@0 149 ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
michael@0 150 : (void)0 )
michael@0 151 #endif
michael@0 152
michael@0 153 // ---------------------------------------------------------------------
michael@0 154
michael@0 155 /*
michael@0 156 * Conditional based on whether the current LOG_TAG is enabled at
michael@0 157 * verbose priority.
michael@0 158 */
michael@0 159 #ifndef IF_LOGV
michael@0 160 #if LOG_NDEBUG
michael@0 161 #define IF_LOGV() if (false)
michael@0 162 #else
michael@0 163 #define IF_LOGV() IF_LOG(LOG_VERBOSE, LOG_TAG)
michael@0 164 #endif
michael@0 165 #endif
michael@0 166
michael@0 167 /*
michael@0 168 * Conditional based on whether the current LOG_TAG is enabled at
michael@0 169 * debug priority.
michael@0 170 */
michael@0 171 #ifndef IF_LOGD
michael@0 172 #define IF_LOGD() IF_LOG(LOG_DEBUG, LOG_TAG)
michael@0 173 #endif
michael@0 174
michael@0 175 /*
michael@0 176 * Conditional based on whether the current LOG_TAG is enabled at
michael@0 177 * info priority.
michael@0 178 */
michael@0 179 #ifndef IF_LOGI
michael@0 180 #define IF_LOGI() IF_LOG(LOG_INFO, LOG_TAG)
michael@0 181 #endif
michael@0 182
michael@0 183 /*
michael@0 184 * Conditional based on whether the current LOG_TAG is enabled at
michael@0 185 * warn priority.
michael@0 186 */
michael@0 187 #ifndef IF_LOGW
michael@0 188 #define IF_LOGW() IF_LOG(LOG_WARN, LOG_TAG)
michael@0 189 #endif
michael@0 190
michael@0 191 /*
michael@0 192 * Conditional based on whether the current LOG_TAG is enabled at
michael@0 193 * error priority.
michael@0 194 */
michael@0 195 #ifndef IF_LOGE
michael@0 196 #define IF_LOGE() IF_LOG(LOG_ERROR, LOG_TAG)
michael@0 197 #endif
michael@0 198
michael@0 199
michael@0 200 // ---------------------------------------------------------------------
michael@0 201
michael@0 202 /*
michael@0 203 * Simplified macro to send a verbose system log message using the current LOG_TAG.
michael@0 204 */
michael@0 205 #ifndef SLOGV
michael@0 206 #if LOG_NDEBUG
michael@0 207 #define SLOGV(...) ((void)0)
michael@0 208 #else
michael@0 209 #define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
michael@0 210 #endif
michael@0 211 #endif
michael@0 212
michael@0 213 #define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
michael@0 214
michael@0 215 #ifndef SLOGV_IF
michael@0 216 #if LOG_NDEBUG
michael@0 217 #define SLOGV_IF(cond, ...) ((void)0)
michael@0 218 #else
michael@0 219 #define SLOGV_IF(cond, ...) \
michael@0 220 ( (CONDITION(cond)) \
michael@0 221 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
michael@0 222 : (void)0 )
michael@0 223 #endif
michael@0 224 #endif
michael@0 225
michael@0 226 /*
michael@0 227 * Simplified macro to send a debug system log message using the current LOG_TAG.
michael@0 228 */
michael@0 229 #ifndef SLOGD
michael@0 230 #define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
michael@0 231 #endif
michael@0 232
michael@0 233 #ifndef SLOGD_IF
michael@0 234 #define SLOGD_IF(cond, ...) \
michael@0 235 ( (CONDITION(cond)) \
michael@0 236 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
michael@0 237 : (void)0 )
michael@0 238 #endif
michael@0 239
michael@0 240 /*
michael@0 241 * Simplified macro to send an info system log message using the current LOG_TAG.
michael@0 242 */
michael@0 243 #ifndef SLOGI
michael@0 244 #define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
michael@0 245 #endif
michael@0 246
michael@0 247 #ifndef SLOGI_IF
michael@0 248 #define SLOGI_IF(cond, ...) \
michael@0 249 ( (CONDITION(cond)) \
michael@0 250 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
michael@0 251 : (void)0 )
michael@0 252 #endif
michael@0 253
michael@0 254 /*
michael@0 255 * Simplified macro to send a warning system log message using the current LOG_TAG.
michael@0 256 */
michael@0 257 #ifndef SLOGW
michael@0 258 #define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
michael@0 259 #endif
michael@0 260
michael@0 261 #ifndef SLOGW_IF
michael@0 262 #define SLOGW_IF(cond, ...) \
michael@0 263 ( (CONDITION(cond)) \
michael@0 264 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
michael@0 265 : (void)0 )
michael@0 266 #endif
michael@0 267
michael@0 268 /*
michael@0 269 * Simplified macro to send an error system log message using the current LOG_TAG.
michael@0 270 */
michael@0 271 #ifndef SLOGE
michael@0 272 #define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
michael@0 273 #endif
michael@0 274
michael@0 275 #ifndef SLOGE_IF
michael@0 276 #define SLOGE_IF(cond, ...) \
michael@0 277 ( (CONDITION(cond)) \
michael@0 278 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
michael@0 279 : (void)0 )
michael@0 280 #endif
michael@0 281
michael@0 282
michael@0 283
michael@0 284 // ---------------------------------------------------------------------
michael@0 285
michael@0 286 /*
michael@0 287 * Log a fatal error. If the given condition fails, this stops program
michael@0 288 * execution like a normal assertion, but also generating the given message.
michael@0 289 * It is NOT stripped from release builds. Note that the condition test
michael@0 290 * is -inverted- from the normal assert() semantics.
michael@0 291 */
michael@0 292 #ifndef LOG_ALWAYS_FATAL_IF
michael@0 293 #define LOG_ALWAYS_FATAL_IF(cond, ...) \
michael@0 294 ( (CONDITION(cond)) \
michael@0 295 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
michael@0 296 : (void)0 )
michael@0 297 #endif
michael@0 298
michael@0 299 #ifndef LOG_ALWAYS_FATAL
michael@0 300 #define LOG_ALWAYS_FATAL(...) \
michael@0 301 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
michael@0 302 #endif
michael@0 303
michael@0 304 /*
michael@0 305 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
michael@0 306 * are stripped out of release builds.
michael@0 307 */
michael@0 308 #if LOG_NDEBUG
michael@0 309
michael@0 310 #ifndef LOG_FATAL_IF
michael@0 311 #define LOG_FATAL_IF(cond, ...) ((void)0)
michael@0 312 #endif
michael@0 313 #ifndef LOG_FATAL
michael@0 314 #define LOG_FATAL(...) ((void)0)
michael@0 315 #endif
michael@0 316
michael@0 317 #else
michael@0 318
michael@0 319 #ifndef LOG_FATAL_IF
michael@0 320 #define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
michael@0 321 #endif
michael@0 322 #ifndef LOG_FATAL
michael@0 323 #define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
michael@0 324 #endif
michael@0 325
michael@0 326 #endif
michael@0 327
michael@0 328 /*
michael@0 329 * Assertion that generates a log message when the assertion fails.
michael@0 330 * Stripped out of release builds. Uses the current LOG_TAG.
michael@0 331 */
michael@0 332 #ifndef LOG_ASSERT
michael@0 333 #define LOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
michael@0 334 //#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
michael@0 335 #endif
michael@0 336
michael@0 337 // ---------------------------------------------------------------------
michael@0 338
michael@0 339 /*
michael@0 340 * Basic log message macro.
michael@0 341 *
michael@0 342 * Example:
michael@0 343 * LOG(LOG_WARN, NULL, "Failed with error %d", errno);
michael@0 344 *
michael@0 345 * The second argument may be NULL or "" to indicate the "global" tag.
michael@0 346 */
michael@0 347 #ifndef LOG
michael@0 348 #define LOG(priority, tag, ...) \
michael@0 349 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
michael@0 350 #endif
michael@0 351
michael@0 352 /*
michael@0 353 * Log macro that allows you to specify a number for the priority.
michael@0 354 */
michael@0 355 #ifndef LOG_PRI
michael@0 356 #define LOG_PRI(priority, tag, ...) \
michael@0 357 android_printLog(priority, tag, __VA_ARGS__)
michael@0 358 #endif
michael@0 359
michael@0 360 /*
michael@0 361 * Log macro that allows you to pass in a varargs ("args" is a va_list).
michael@0 362 */
michael@0 363 #ifndef LOG_PRI_VA
michael@0 364 #define LOG_PRI_VA(priority, tag, fmt, args) \
michael@0 365 android_vprintLog(priority, NULL, tag, fmt, args)
michael@0 366 #endif
michael@0 367
michael@0 368 /*
michael@0 369 * Conditional given a desired logging priority and tag.
michael@0 370 */
michael@0 371 #ifndef IF_LOG
michael@0 372 #define IF_LOG(priority, tag) \
michael@0 373 if (android_testLog(ANDROID_##priority, tag))
michael@0 374 #endif
michael@0 375
michael@0 376 // ---------------------------------------------------------------------
michael@0 377
michael@0 378 /*
michael@0 379 * Event logging.
michael@0 380 */
michael@0 381
michael@0 382 /*
michael@0 383 * Event log entry types. These must match up with the declarations in
michael@0 384 * java/android/android/util/EventLog.java.
michael@0 385 */
michael@0 386 typedef enum {
michael@0 387 EVENT_TYPE_INT = 0,
michael@0 388 EVENT_TYPE_LONG = 1,
michael@0 389 EVENT_TYPE_STRING = 2,
michael@0 390 EVENT_TYPE_LIST = 3,
michael@0 391 } AndroidEventLogType;
michael@0 392
michael@0 393
michael@0 394 #ifndef LOG_EVENT_INT
michael@0 395 #define LOG_EVENT_INT(_tag, _value) { \
michael@0 396 int intBuf = _value; \
michael@0 397 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
michael@0 398 sizeof(intBuf)); \
michael@0 399 }
michael@0 400 #endif
michael@0 401 #ifndef LOG_EVENT_LONG
michael@0 402 #define LOG_EVENT_LONG(_tag, _value) { \
michael@0 403 long long longBuf = _value; \
michael@0 404 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
michael@0 405 sizeof(longBuf)); \
michael@0 406 }
michael@0 407 #endif
michael@0 408 #ifndef LOG_EVENT_STRING
michael@0 409 #define LOG_EVENT_STRING(_tag, _value) \
michael@0 410 ((void) 0) /* not implemented -- must combine len with string */
michael@0 411 #endif
michael@0 412 /* TODO: something for LIST */
michael@0 413
michael@0 414 /*
michael@0 415 * ===========================================================================
michael@0 416 *
michael@0 417 * The stuff in the rest of this file should not be used directly.
michael@0 418 */
michael@0 419
michael@0 420 #define android_printLog(prio, tag, fmt...) \
michael@0 421 __android_log_print(prio, tag, fmt)
michael@0 422
michael@0 423 #define android_vprintLog(prio, cond, tag, fmt...) \
michael@0 424 __android_log_vprint(prio, tag, fmt)
michael@0 425
michael@0 426 /* XXX Macros to work around syntax errors in places where format string
michael@0 427 * arg is not passed to LOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
michael@0 428 * (happens only in debug builds).
michael@0 429 */
michael@0 430
michael@0 431 /* Returns 2nd arg. Used to substitute default value if caller's vararg list
michael@0 432 * is empty.
michael@0 433 */
michael@0 434 #define __android_second(dummy, second, ...) second
michael@0 435
michael@0 436 /* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
michael@0 437 * returns nothing.
michael@0 438 */
michael@0 439 #define __android_rest(first, ...) , ## __VA_ARGS__
michael@0 440
michael@0 441 #define android_printAssert(cond, tag, fmt...) \
michael@0 442 __android_log_assert(cond, tag, \
michael@0 443 __android_second(0, ## fmt, NULL) __android_rest(fmt))
michael@0 444
michael@0 445 #define android_writeLog(prio, tag, text) \
michael@0 446 __android_log_write(prio, tag, text)
michael@0 447
michael@0 448 #define android_bWriteLog(tag, payload, len) \
michael@0 449 __android_log_bwrite(tag, payload, len)
michael@0 450 #define android_btWriteLog(tag, type, payload, len) \
michael@0 451 __android_log_btwrite(tag, type, payload, len)
michael@0 452
michael@0 453 // TODO: remove these prototypes and their users
michael@0 454 #define android_testLog(prio, tag) (1)
michael@0 455 #define android_writevLog(vec,num) do{}while(0)
michael@0 456 #define android_write1Log(str,len) do{}while (0)
michael@0 457 #define android_setMinPriority(tag, prio) do{}while(0)
michael@0 458 //#define android_logToCallback(func) do{}while(0)
michael@0 459 #define android_logToFile(tag, file) (0)
michael@0 460 #define android_logToFd(tag, fd) (0)
michael@0 461
michael@0 462 typedef enum {
michael@0 463 LOG_ID_MAIN = 0,
michael@0 464 LOG_ID_RADIO = 1,
michael@0 465 LOG_ID_EVENTS = 2,
michael@0 466 LOG_ID_SYSTEM = 3,
michael@0 467
michael@0 468 LOG_ID_MAX
michael@0 469 } log_id_t;
michael@0 470
michael@0 471 /*
michael@0 472 * Send a simple string to the log.
michael@0 473 */
michael@0 474 int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
michael@0 475 int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
michael@0 476
michael@0 477
michael@0 478 #ifdef __cplusplus
michael@0 479 }
michael@0 480 #endif
michael@0 481
michael@0 482 #endif // _LIBS_CUTILS_LOG_H

mercurial