The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 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_CUTILS_LOG_H |
| 29 | #define _LIBS_CUTILS_LOG_H |
| 30 | |
| 31 | #include <stdio.h> |
| 32 | #include <time.h> |
| 33 | #include <sys/types.h> |
| 34 | #include <unistd.h> |
| 35 | #ifdef HAVE_PTHREADS |
| 36 | #include <pthread.h> |
| 37 | #endif |
| 38 | #include <stdarg.h> |
| 39 | |
| 40 | #include <cutils/uio.h> |
| 41 | #include <cutils/logd.h> |
| 42 | |
| 43 | #ifdef __cplusplus |
| 44 | extern "C" { |
| 45 | #endif |
| 46 | |
| 47 | // --------------------------------------------------------------------- |
| 48 | |
| 49 | /* |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 50 | * Normally we strip ALOGV (VERBOSE messages) from release builds. |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 51 | * You can modify this (for example with "#define LOG_NDEBUG 0" |
| 52 | * at the top of your source file) to change that behavior. |
| 53 | */ |
| 54 | #ifndef LOG_NDEBUG |
| 55 | #ifdef NDEBUG |
| 56 | #define LOG_NDEBUG 1 |
| 57 | #else |
| 58 | #define LOG_NDEBUG 0 |
| 59 | #endif |
| 60 | #endif |
| 61 | |
| 62 | /* |
| 63 | * This is the local tag used for the following simplified |
| 64 | * logging macros. You can change this preprocessor definition |
| 65 | * before using the other macros to change the tag. |
| 66 | */ |
| 67 | #ifndef LOG_TAG |
| 68 | #define LOG_TAG NULL |
| 69 | #endif |
| 70 | |
| 71 | // --------------------------------------------------------------------- |
| 72 | |
| 73 | /* |
| 74 | * Simplified macro to send a verbose log message using the current LOG_TAG. |
| 75 | */ |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 76 | #ifndef ALOGV |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 77 | #if LOG_NDEBUG |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 78 | #define ALOGV(...) ((void)0) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 79 | #else |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 80 | #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 81 | #endif |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 82 | // Temporary measure for code still using old LOG macros. |
| 83 | #ifndef LOGV |
| 84 | #define LOGV ALOGV |
| 85 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 86 | #endif |
| 87 | |
| 88 | #define CONDITION(cond) (__builtin_expect((cond)!=0, 0)) |
| 89 | |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 90 | #ifndef ALOGV_IF |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 91 | #if LOG_NDEBUG |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 92 | #define ALOGV_IF(cond, ...) ((void)0) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 93 | #else |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 94 | #define ALOGV_IF(cond, ...) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 95 | ( (CONDITION(cond)) \ |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 96 | ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 97 | : (void)0 ) |
| 98 | #endif |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 99 | // Temporary measure for code still using old LOG macros. |
| 100 | #ifndef LOGV_IF |
| 101 | #define LOGV_IF ALOGV_IF |
| 102 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 103 | #endif |
| 104 | |
| 105 | /* |
| 106 | * Simplified macro to send a debug log message using the current LOG_TAG. |
| 107 | */ |
Steve Block | 9786ec4 | 2011-12-20 16:07:45 +0000 | [diff] [blame] | 108 | #ifndef ALOGD |
| 109 | #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) |
| 110 | // Temporary measure for code still using old LOG macros. |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 111 | #ifndef LOGD |
Steve Block | 9786ec4 | 2011-12-20 16:07:45 +0000 | [diff] [blame] | 112 | #define LOGD ALOGD |
| 113 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 114 | #endif |
| 115 | |
Steve Block | 9786ec4 | 2011-12-20 16:07:45 +0000 | [diff] [blame] | 116 | #ifndef ALOGD_IF |
| 117 | #define ALOGD_IF(cond, ...) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 118 | ( (CONDITION(cond)) \ |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 119 | ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 120 | : (void)0 ) |
Steve Block | 9786ec4 | 2011-12-20 16:07:45 +0000 | [diff] [blame] | 121 | // Temporary measure for code still using old LOG macros. |
| 122 | #ifndef LOGD_IF |
| 123 | #define LOGD_IF ALOGD_IF |
| 124 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 125 | #endif |
| 126 | |
| 127 | /* |
| 128 | * Simplified macro to send an info log message using the current LOG_TAG. |
| 129 | */ |
Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame^] | 130 | #ifndef ALOGI |
| 131 | #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) |
| 132 | // Temporary measure for code still using old LOG macros. |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 133 | #ifndef LOGI |
Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame^] | 134 | #define LOGI ALOGI |
| 135 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 136 | #endif |
| 137 | |
Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame^] | 138 | #ifndef ALOGI_IF |
| 139 | #define ALOGI_IF(cond, ...) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 140 | ( (CONDITION(cond)) \ |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 141 | ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 142 | : (void)0 ) |
Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame^] | 143 | // Temporary measure for code still using old LOG macros. |
| 144 | #ifndef LOGI_IF |
| 145 | #define LOGI_IF ALOGI_IF |
| 146 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 147 | #endif |
| 148 | |
| 149 | /* |
| 150 | * Simplified macro to send a warning log message using the current LOG_TAG. |
| 151 | */ |
| 152 | #ifndef LOGW |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 153 | #define LOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) |
Steve Block | e7e7fac | 2011-12-22 15:00:35 +0000 | [diff] [blame] | 154 | #define ALOGW LOGW |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 155 | #endif |
| 156 | |
| 157 | #ifndef LOGW_IF |
| 158 | #define LOGW_IF(cond, ...) \ |
| 159 | ( (CONDITION(cond)) \ |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 160 | ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 161 | : (void)0 ) |
Steve Block | e7e7fac | 2011-12-22 15:00:35 +0000 | [diff] [blame] | 162 | #define ALOGW_IF LOGW_IF |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 163 | #endif |
| 164 | |
| 165 | /* |
| 166 | * Simplified macro to send an error log message using the current LOG_TAG. |
| 167 | */ |
| 168 | #ifndef LOGE |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 169 | #define LOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) |
Steve Block | e7e7fac | 2011-12-22 15:00:35 +0000 | [diff] [blame] | 170 | #define ALOGE LOGE |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 171 | #endif |
| 172 | |
| 173 | #ifndef LOGE_IF |
| 174 | #define LOGE_IF(cond, ...) \ |
| 175 | ( (CONDITION(cond)) \ |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 176 | ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 177 | : (void)0 ) |
Steve Block | e7e7fac | 2011-12-22 15:00:35 +0000 | [diff] [blame] | 178 | #define ALOGE_IF LOGE_IF |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 179 | #endif |
| 180 | |
| 181 | // --------------------------------------------------------------------- |
| 182 | |
| 183 | /* |
| 184 | * Conditional based on whether the current LOG_TAG is enabled at |
| 185 | * verbose priority. |
| 186 | */ |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 187 | #ifndef IF_ALOGV |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 188 | #if LOG_NDEBUG |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 189 | #define IF_ALOGV() if (false) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 190 | #else |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 191 | #define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 192 | #endif |
Steve Block | 66b6875 | 2011-10-20 11:54:09 +0100 | [diff] [blame] | 193 | // Temporary measure for code still using old LOG macros. |
| 194 | #ifndef IF_LOGV |
| 195 | #define IF_LOGV IF_ALOGV |
| 196 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 197 | #endif |
| 198 | |
| 199 | /* |
| 200 | * Conditional based on whether the current LOG_TAG is enabled at |
| 201 | * debug priority. |
| 202 | */ |
Steve Block | 9786ec4 | 2011-12-20 16:07:45 +0000 | [diff] [blame] | 203 | #ifndef IF_ALOGD |
| 204 | #define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG) |
| 205 | // Temporary measure for code still using old LOG macros. |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 206 | #ifndef IF_LOGD |
Steve Block | 9786ec4 | 2011-12-20 16:07:45 +0000 | [diff] [blame] | 207 | #define IF_LOGD IF_ALOGD |
| 208 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 209 | #endif |
| 210 | |
| 211 | /* |
| 212 | * Conditional based on whether the current LOG_TAG is enabled at |
| 213 | * info priority. |
| 214 | */ |
Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame^] | 215 | #ifndef IF_ALOGI |
| 216 | #define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG) |
| 217 | // Temporary measure for code still using old LOG macros. |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 218 | #ifndef IF_LOGI |
Steve Block | 4163b45 | 2012-01-04 19:19:03 +0000 | [diff] [blame^] | 219 | #define IF_LOGI IF_ALOGI |
| 220 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 221 | #endif |
| 222 | |
| 223 | /* |
| 224 | * Conditional based on whether the current LOG_TAG is enabled at |
| 225 | * warn priority. |
| 226 | */ |
| 227 | #ifndef IF_LOGW |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 228 | #define IF_LOGW() IF_ALOG(LOG_WARN, LOG_TAG) |
Steve Block | e7e7fac | 2011-12-22 15:00:35 +0000 | [diff] [blame] | 229 | #define IF_ALOGW IF_LOGW |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 230 | #endif |
| 231 | |
| 232 | /* |
| 233 | * Conditional based on whether the current LOG_TAG is enabled at |
| 234 | * error priority. |
| 235 | */ |
| 236 | #ifndef IF_LOGE |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 237 | #define IF_LOGE() IF_ALOG(LOG_ERROR, LOG_TAG) |
Steve Block | e7e7fac | 2011-12-22 15:00:35 +0000 | [diff] [blame] | 238 | #define IF_ALOGE IF_LOGE |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 239 | #endif |
| 240 | |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 241 | |
| 242 | // --------------------------------------------------------------------- |
| 243 | |
| 244 | /* |
| 245 | * Simplified macro to send a verbose system log message using the current LOG_TAG. |
| 246 | */ |
| 247 | #ifndef SLOGV |
| 248 | #if LOG_NDEBUG |
| 249 | #define SLOGV(...) ((void)0) |
| 250 | #else |
| 251 | #define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) |
| 252 | #endif |
| 253 | #endif |
| 254 | |
| 255 | #define CONDITION(cond) (__builtin_expect((cond)!=0, 0)) |
| 256 | |
| 257 | #ifndef SLOGV_IF |
| 258 | #if LOG_NDEBUG |
| 259 | #define SLOGV_IF(cond, ...) ((void)0) |
| 260 | #else |
| 261 | #define SLOGV_IF(cond, ...) \ |
| 262 | ( (CONDITION(cond)) \ |
| 263 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ |
| 264 | : (void)0 ) |
| 265 | #endif |
| 266 | #endif |
| 267 | |
| 268 | /* |
| 269 | * Simplified macro to send a debug system log message using the current LOG_TAG. |
| 270 | */ |
| 271 | #ifndef SLOGD |
| 272 | #define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) |
| 273 | #endif |
| 274 | |
| 275 | #ifndef SLOGD_IF |
| 276 | #define SLOGD_IF(cond, ...) \ |
| 277 | ( (CONDITION(cond)) \ |
| 278 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ |
| 279 | : (void)0 ) |
| 280 | #endif |
| 281 | |
| 282 | /* |
| 283 | * Simplified macro to send an info system log message using the current LOG_TAG. |
| 284 | */ |
| 285 | #ifndef SLOGI |
| 286 | #define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) |
| 287 | #endif |
| 288 | |
| 289 | #ifndef SLOGI_IF |
| 290 | #define SLOGI_IF(cond, ...) \ |
| 291 | ( (CONDITION(cond)) \ |
| 292 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \ |
| 293 | : (void)0 ) |
| 294 | #endif |
| 295 | |
| 296 | /* |
| 297 | * Simplified macro to send a warning system log message using the current LOG_TAG. |
| 298 | */ |
| 299 | #ifndef SLOGW |
| 300 | #define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) |
| 301 | #endif |
| 302 | |
| 303 | #ifndef SLOGW_IF |
| 304 | #define SLOGW_IF(cond, ...) \ |
| 305 | ( (CONDITION(cond)) \ |
| 306 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \ |
| 307 | : (void)0 ) |
| 308 | #endif |
| 309 | |
| 310 | /* |
| 311 | * Simplified macro to send an error system log message using the current LOG_TAG. |
| 312 | */ |
| 313 | #ifndef SLOGE |
| 314 | #define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) |
| 315 | #endif |
| 316 | |
| 317 | #ifndef SLOGE_IF |
| 318 | #define SLOGE_IF(cond, ...) \ |
| 319 | ( (CONDITION(cond)) \ |
| 320 | ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ |
| 321 | : (void)0 ) |
| 322 | #endif |
| 323 | |
| 324 | |
| 325 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 326 | // --------------------------------------------------------------------- |
| 327 | |
| 328 | /* |
| 329 | * Log a fatal error. If the given condition fails, this stops program |
| 330 | * execution like a normal assertion, but also generating the given message. |
| 331 | * It is NOT stripped from release builds. Note that the condition test |
| 332 | * is -inverted- from the normal assert() semantics. |
| 333 | */ |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 334 | #ifndef LOG_ALWAYS_FATAL_IF |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 335 | #define LOG_ALWAYS_FATAL_IF(cond, ...) \ |
| 336 | ( (CONDITION(cond)) \ |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 337 | ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 338 | : (void)0 ) |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 339 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 340 | |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 341 | #ifndef LOG_ALWAYS_FATAL |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 342 | #define LOG_ALWAYS_FATAL(...) \ |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 343 | ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) ) |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 344 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 345 | |
| 346 | /* |
| 347 | * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that |
| 348 | * are stripped out of release builds. |
| 349 | */ |
| 350 | #if LOG_NDEBUG |
| 351 | |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 352 | #ifndef LOG_FATAL_IF |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 353 | #define LOG_FATAL_IF(cond, ...) ((void)0) |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 354 | #endif |
| 355 | #ifndef LOG_FATAL |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 356 | #define LOG_FATAL(...) ((void)0) |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 357 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 358 | |
| 359 | #else |
| 360 | |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 361 | #ifndef LOG_FATAL_IF |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 362 | #define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__) |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 363 | #endif |
| 364 | #ifndef LOG_FATAL |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 365 | #define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__) |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 366 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 367 | |
| 368 | #endif |
| 369 | |
| 370 | /* |
| 371 | * Assertion that generates a log message when the assertion fails. |
| 372 | * Stripped out of release builds. Uses the current LOG_TAG. |
| 373 | */ |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 374 | #ifndef LOG_ASSERT |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 375 | #define LOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 376 | //#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond) |
Steve Block | a9b84a7 | 2012-01-09 22:50:36 +0000 | [diff] [blame] | 377 | #define ALOG_ASSERT LOG_ASSERT |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 378 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 379 | |
| 380 | // --------------------------------------------------------------------- |
| 381 | |
| 382 | /* |
| 383 | * Basic log message macro. |
| 384 | * |
| 385 | * Example: |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 386 | * ALOG(LOG_WARN, NULL, "Failed with error %d", errno); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 387 | * |
| 388 | * The second argument may be NULL or "" to indicate the "global" tag. |
| 389 | */ |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 390 | #ifndef ALOG |
| 391 | #define ALOG(priority, tag, ...) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 392 | LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 393 | // Temporary measure for code still using old LOG macros. |
| 394 | #ifndef LOG |
| 395 | #define LOG ALOG |
| 396 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 397 | #endif |
| 398 | |
| 399 | /* |
| 400 | * Log macro that allows you to specify a number for the priority. |
| 401 | */ |
| 402 | #ifndef LOG_PRI |
| 403 | #define LOG_PRI(priority, tag, ...) \ |
| 404 | android_printLog(priority, tag, __VA_ARGS__) |
| 405 | #endif |
| 406 | |
| 407 | /* |
| 408 | * Log macro that allows you to pass in a varargs ("args" is a va_list). |
| 409 | */ |
| 410 | #ifndef LOG_PRI_VA |
| 411 | #define LOG_PRI_VA(priority, tag, fmt, args) \ |
| 412 | android_vprintLog(priority, NULL, tag, fmt, args) |
| 413 | #endif |
| 414 | |
| 415 | /* |
| 416 | * Conditional given a desired logging priority and tag. |
| 417 | */ |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 418 | #ifndef IF_ALOG |
| 419 | #define IF_ALOG(priority, tag) \ |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 420 | if (android_testLog(ANDROID_##priority, tag)) |
Steve Block | 61fbcbe | 2011-10-12 17:22:43 +0100 | [diff] [blame] | 421 | // Temporary measure for code still using old LOG macros. |
| 422 | #ifndef IF_LOG |
| 423 | #define IF_LOG IF_ALOG |
| 424 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 425 | #endif |
| 426 | |
| 427 | // --------------------------------------------------------------------- |
| 428 | |
| 429 | /* |
| 430 | * Event logging. |
| 431 | */ |
| 432 | |
| 433 | /* |
| 434 | * Event log entry types. These must match up with the declarations in |
| 435 | * java/android/android/util/EventLog.java. |
| 436 | */ |
| 437 | typedef enum { |
| 438 | EVENT_TYPE_INT = 0, |
| 439 | EVENT_TYPE_LONG = 1, |
| 440 | EVENT_TYPE_STRING = 2, |
| 441 | EVENT_TYPE_LIST = 3, |
| 442 | } AndroidEventLogType; |
| 443 | |
| 444 | |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 445 | #ifndef LOG_EVENT_INT |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 446 | #define LOG_EVENT_INT(_tag, _value) { \ |
| 447 | int intBuf = _value; \ |
| 448 | (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \ |
| 449 | sizeof(intBuf)); \ |
| 450 | } |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 451 | #endif |
| 452 | #ifndef LOG_EVENT_LONG |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 453 | #define LOG_EVENT_LONG(_tag, _value) { \ |
| 454 | long long longBuf = _value; \ |
| 455 | (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \ |
| 456 | sizeof(longBuf)); \ |
| 457 | } |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 458 | #endif |
| 459 | #ifndef LOG_EVENT_STRING |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 460 | #define LOG_EVENT_STRING(_tag, _value) \ |
| 461 | ((void) 0) /* not implemented -- must combine len with string */ |
Alexandre Elias | 412514e | 2011-03-29 16:24:45 -0700 | [diff] [blame] | 462 | #endif |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 463 | /* TODO: something for LIST */ |
| 464 | |
| 465 | /* |
| 466 | * =========================================================================== |
| 467 | * |
| 468 | * The stuff in the rest of this file should not be used directly. |
| 469 | */ |
| 470 | |
| 471 | #define android_printLog(prio, tag, fmt...) \ |
| 472 | __android_log_print(prio, tag, fmt) |
| 473 | |
| 474 | #define android_vprintLog(prio, cond, tag, fmt...) \ |
| 475 | __android_log_vprint(prio, tag, fmt) |
| 476 | |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 477 | /* XXX Macros to work around syntax errors in places where format string |
| 478 | * arg is not passed to LOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF |
| 479 | * (happens only in debug builds). |
| 480 | */ |
| 481 | |
| 482 | /* Returns 2nd arg. Used to substitute default value if caller's vararg list |
| 483 | * is empty. |
| 484 | */ |
| 485 | #define __android_second(dummy, second, ...) second |
| 486 | |
| 487 | /* If passed multiple args, returns ',' followed by all but 1st arg, otherwise |
| 488 | * returns nothing. |
| 489 | */ |
| 490 | #define __android_rest(first, ...) , ## __VA_ARGS__ |
| 491 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 492 | #define android_printAssert(cond, tag, fmt...) \ |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 493 | __android_log_assert(cond, tag, \ |
| 494 | __android_second(0, ## fmt, NULL) __android_rest(fmt)) |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 495 | |
| 496 | #define android_writeLog(prio, tag, text) \ |
| 497 | __android_log_write(prio, tag, text) |
| 498 | |
| 499 | #define android_bWriteLog(tag, payload, len) \ |
| 500 | __android_log_bwrite(tag, payload, len) |
| 501 | #define android_btWriteLog(tag, type, payload, len) \ |
| 502 | __android_log_btwrite(tag, type, payload, len) |
Chris Pearson | 1929990 | 2010-06-02 16:25:35 -0700 | [diff] [blame] | 503 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 504 | // TODO: remove these prototypes and their users |
| 505 | #define android_testLog(prio, tag) (1) |
| 506 | #define android_writevLog(vec,num) do{}while(0) |
| 507 | #define android_write1Log(str,len) do{}while (0) |
| 508 | #define android_setMinPriority(tag, prio) do{}while(0) |
| 509 | //#define android_logToCallback(func) do{}while(0) |
| 510 | #define android_logToFile(tag, file) (0) |
| 511 | #define android_logToFd(tag, fd) (0) |
| 512 | |
Joe Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 513 | typedef enum { |
| 514 | LOG_ID_MAIN = 0, |
| 515 | LOG_ID_RADIO = 1, |
| 516 | LOG_ID_EVENTS = 2, |
| 517 | LOG_ID_SYSTEM = 3, |
| 518 | |
| 519 | LOG_ID_MAX |
| 520 | } log_id_t; |
| 521 | |
| 522 | /* |
| 523 | * Send a simple string to the log. |
| 524 | */ |
| 525 | int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text); |
| 526 | int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...); |
| 527 | |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 528 | |
| 529 | #ifdef __cplusplus |
| 530 | } |
| 531 | #endif |
| 532 | |
| 533 | #endif // _LIBS_CUTILS_LOG_H |