Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / third_party / hwcplus / include / log / log.h
blob4677ed4d9336cc82ae2df01b730d3804f0be79b8
1 /*
2 * Copyright (C) 2005 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 // C/C++ logging functions. See the logging documentation for API details.
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.
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.
28 #ifndef _LIBS_LOG_LOG_H
29 #define _LIBS_LOG_LOG_H
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>
40 #ifdef ANDROID
41 #include <log/uio.h>
42 #include <log/logd.h>
43 #else
44 #include <android/log.h>
45 #endif
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
51 // ---------------------------------------------------------------------
54 * Normally we strip ALOGV (VERBOSE messages) from release builds.
55 * You can modify this (for example with "#define LOG_NDEBUG 0"
56 * at the top of your source file) to change that behavior.
58 #ifndef LOG_NDEBUG
59 #ifdef NDEBUG
60 #define LOG_NDEBUG 1
61 #else
62 #define LOG_NDEBUG 0
63 #endif
64 #endif
67 * This is the local tag used for the following simplified
68 * logging macros. You can change this preprocessor definition
69 * before using the other macros to change the tag.
71 #ifndef LOG_TAG
72 #define LOG_TAG NULL
73 #endif
75 // ---------------------------------------------------------------------
78 * Simplified macro to send a verbose log message using the current LOG_TAG.
80 #ifndef ALOGV
81 #if LOG_NDEBUG
82 #define ALOGV(...) ((void)0)
83 #else
84 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
85 #endif
86 #endif
88 #define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
90 #ifndef ALOGV_IF
91 #if LOG_NDEBUG
92 #define ALOGV_IF(cond, ...) ((void)0)
93 #else
94 #define ALOGV_IF(cond, ...) \
95 ( (CONDITION(cond)) \
96 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
97 : (void)0 )
98 #endif
99 #endif
102 * Simplified macro to send a debug log message using the current LOG_TAG.
104 #ifndef ALOGD
105 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
106 #endif
108 #ifndef ALOGD_IF
109 #define ALOGD_IF(cond, ...) \
110 ( (CONDITION(cond)) \
111 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
112 : (void)0 )
113 #endif
116 * Simplified macro to send an info log message using the current LOG_TAG.
118 #ifndef ALOGI
119 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
120 #endif
122 #ifndef ALOGI_IF
123 #define ALOGI_IF(cond, ...) \
124 ( (CONDITION(cond)) \
125 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
126 : (void)0 )
127 #endif
130 * Simplified macro to send a warning log message using the current LOG_TAG.
132 #ifndef ALOGW
133 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
134 #endif
136 #ifndef ALOGW_IF
137 #define ALOGW_IF(cond, ...) \
138 ( (CONDITION(cond)) \
139 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
140 : (void)0 )
141 #endif
144 * Simplified macro to send an error log message using the current LOG_TAG.
146 #ifndef ALOGE
147 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
148 #endif
150 #ifndef ALOGE_IF
151 #define ALOGE_IF(cond, ...) \
152 ( (CONDITION(cond)) \
153 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
154 : (void)0 )
155 #endif
157 // ---------------------------------------------------------------------
160 * Conditional based on whether the current LOG_TAG is enabled at
161 * verbose priority.
163 #ifndef IF_ALOGV
164 #if LOG_NDEBUG
165 #define IF_ALOGV() if (false)
166 #else
167 #define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
168 #endif
169 #endif
172 * Conditional based on whether the current LOG_TAG is enabled at
173 * debug priority.
175 #ifndef IF_ALOGD
176 #define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
177 #endif
180 * Conditional based on whether the current LOG_TAG is enabled at
181 * info priority.
183 #ifndef IF_ALOGI
184 #define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
185 #endif
188 * Conditional based on whether the current LOG_TAG is enabled at
189 * warn priority.
191 #ifndef IF_ALOGW
192 #define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
193 #endif
196 * Conditional based on whether the current LOG_TAG is enabled at
197 * error priority.
199 #ifndef IF_ALOGE
200 #define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
201 #endif
204 // ---------------------------------------------------------------------
207 * Simplified macro to send a verbose system log message using the current LOG_TAG.
209 #ifndef SLOGV
210 #if LOG_NDEBUG
211 #define SLOGV(...) ((void)0)
212 #else
213 #define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
214 #endif
215 #endif
217 #define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
219 #ifndef SLOGV_IF
220 #if LOG_NDEBUG
221 #define SLOGV_IF(cond, ...) ((void)0)
222 #else
223 #define SLOGV_IF(cond, ...) \
224 ( (CONDITION(cond)) \
225 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
226 : (void)0 )
227 #endif
228 #endif
231 * Simplified macro to send a debug system log message using the current LOG_TAG.
233 #ifndef SLOGD
234 #define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
235 #endif
237 #ifndef SLOGD_IF
238 #define SLOGD_IF(cond, ...) \
239 ( (CONDITION(cond)) \
240 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
241 : (void)0 )
242 #endif
245 * Simplified macro to send an info system log message using the current LOG_TAG.
247 #ifndef SLOGI
248 #define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
249 #endif
251 #ifndef SLOGI_IF
252 #define SLOGI_IF(cond, ...) \
253 ( (CONDITION(cond)) \
254 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
255 : (void)0 )
256 #endif
259 * Simplified macro to send a warning system log message using the current LOG_TAG.
261 #ifndef SLOGW
262 #define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
263 #endif
265 #ifndef SLOGW_IF
266 #define SLOGW_IF(cond, ...) \
267 ( (CONDITION(cond)) \
268 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
269 : (void)0 )
270 #endif
273 * Simplified macro to send an error system log message using the current LOG_TAG.
275 #ifndef SLOGE
276 #define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
277 #endif
279 #ifndef SLOGE_IF
280 #define SLOGE_IF(cond, ...) \
281 ( (CONDITION(cond)) \
282 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
283 : (void)0 )
284 #endif
286 // ---------------------------------------------------------------------
289 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
291 #ifndef RLOGV
292 #if LOG_NDEBUG
293 #define RLOGV(...) ((void)0)
294 #else
295 #define RLOGV(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
296 #endif
297 #endif
299 #define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
301 #ifndef RLOGV_IF
302 #if LOG_NDEBUG
303 #define RLOGV_IF(cond, ...) ((void)0)
304 #else
305 #define RLOGV_IF(cond, ...) \
306 ( (CONDITION(cond)) \
307 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
308 : (void)0 )
309 #endif
310 #endif
313 * Simplified macro to send a debug radio log message using the current LOG_TAG.
315 #ifndef RLOGD
316 #define RLOGD(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
317 #endif
319 #ifndef RLOGD_IF
320 #define RLOGD_IF(cond, ...) \
321 ( (CONDITION(cond)) \
322 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
323 : (void)0 )
324 #endif
327 * Simplified macro to send an info radio log message using the current LOG_TAG.
329 #ifndef RLOGI
330 #define RLOGI(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
331 #endif
333 #ifndef RLOGI_IF
334 #define RLOGI_IF(cond, ...) \
335 ( (CONDITION(cond)) \
336 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
337 : (void)0 )
338 #endif
341 * Simplified macro to send a warning radio log message using the current LOG_TAG.
343 #ifndef RLOGW
344 #define RLOGW(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
345 #endif
347 #ifndef RLOGW_IF
348 #define RLOGW_IF(cond, ...) \
349 ( (CONDITION(cond)) \
350 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
351 : (void)0 )
352 #endif
355 * Simplified macro to send an error radio log message using the current LOG_TAG.
357 #ifndef RLOGE
358 #define RLOGE(...) ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
359 #endif
361 #ifndef RLOGE_IF
362 #define RLOGE_IF(cond, ...) \
363 ( (CONDITION(cond)) \
364 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
365 : (void)0 )
366 #endif
369 // ---------------------------------------------------------------------
372 * Log a fatal error. If the given condition fails, this stops program
373 * execution like a normal assertion, but also generating the given message.
374 * It is NOT stripped from release builds. Note that the condition test
375 * is -inverted- from the normal assert() semantics.
377 #ifndef LOG_ALWAYS_FATAL_IF
378 #define LOG_ALWAYS_FATAL_IF(cond, ...) \
379 ( (CONDITION(cond)) \
380 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
381 : (void)0 )
382 #endif
384 #ifndef LOG_ALWAYS_FATAL
385 #define LOG_ALWAYS_FATAL(...) \
386 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
387 #endif
390 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
391 * are stripped out of release builds.
393 #if LOG_NDEBUG
395 #ifndef LOG_FATAL_IF
396 #define LOG_FATAL_IF(cond, ...) ((void)0)
397 #endif
398 #ifndef LOG_FATAL
399 #define LOG_FATAL(...) ((void)0)
400 #endif
402 #else
404 #ifndef LOG_FATAL_IF
405 #define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
406 #endif
407 #ifndef LOG_FATAL
408 #define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
409 #endif
411 #endif
414 * Assertion that generates a log message when the assertion fails.
415 * Stripped out of release builds. Uses the current LOG_TAG.
417 #ifndef ALOG_ASSERT
418 #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
419 //#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
420 #endif
422 // ---------------------------------------------------------------------
425 * Basic log message macro.
427 * Example:
428 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
430 * The second argument may be NULL or "" to indicate the "global" tag.
432 #ifndef ALOG
433 #define ALOG(priority, tag, ...) \
434 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
435 #endif
438 * Log macro that allows you to specify a number for the priority.
440 #ifndef LOG_PRI
441 #define LOG_PRI(priority, tag, ...) \
442 android_printLog(priority, tag, __VA_ARGS__)
443 #endif
446 * Log macro that allows you to pass in a varargs ("args" is a va_list).
448 #ifndef LOG_PRI_VA
449 #define LOG_PRI_VA(priority, tag, fmt, args) \
450 android_vprintLog(priority, NULL, tag, fmt, args)
451 #endif
454 * Conditional given a desired logging priority and tag.
456 #ifndef IF_ALOG
457 #define IF_ALOG(priority, tag) \
458 if (android_testLog(ANDROID_##priority, tag))
459 #endif
461 // ---------------------------------------------------------------------
464 * Event logging.
468 * Event log entry types. These must match up with the declarations in
469 * java/android/android/util/EventLog.java.
471 typedef enum {
472 EVENT_TYPE_INT = 0,
473 EVENT_TYPE_LONG = 1,
474 EVENT_TYPE_STRING = 2,
475 EVENT_TYPE_LIST = 3,
476 } AndroidEventLogType;
479 #ifndef LOG_EVENT_INT
480 #define LOG_EVENT_INT(_tag, _value) { \
481 int intBuf = _value; \
482 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
483 sizeof(intBuf)); \
485 #endif
486 #ifndef LOG_EVENT_LONG
487 #define LOG_EVENT_LONG(_tag, _value) { \
488 long long longBuf = _value; \
489 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
490 sizeof(longBuf)); \
492 #endif
493 #ifndef LOG_EVENT_STRING
494 #define LOG_EVENT_STRING(_tag, _value) \
495 ((void) 0) /* not implemented -- must combine len with string */
496 #endif
497 /* TODO: something for LIST */
500 * ===========================================================================
502 * The stuff in the rest of this file should not be used directly.
505 #define android_printLog(prio, tag, fmt...) \
506 __android_log_print(prio, tag, fmt)
508 #define android_vprintLog(prio, cond, tag, fmt...) \
509 __android_log_vprint(prio, tag, fmt)
511 /* XXX Macros to work around syntax errors in places where format string
512 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
513 * (happens only in debug builds).
516 /* Returns 2nd arg. Used to substitute default value if caller's vararg list
517 * is empty.
519 #define __android_second(dummy, second, ...) second
521 /* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
522 * returns nothing.
524 #define __android_rest(first, ...) , ## __VA_ARGS__
526 #define android_printAssert(cond, tag, fmt...) \
527 __android_log_assert(cond, tag, \
528 __android_second(0, ## fmt, NULL) __android_rest(fmt))
530 #define android_writeLog(prio, tag, text) \
531 __android_log_write(prio, tag, text)
533 #define android_bWriteLog(tag, payload, len) \
534 __android_log_bwrite(tag, payload, len)
535 #define android_btWriteLog(tag, type, payload, len) \
536 __android_log_btwrite(tag, type, payload, len)
538 // TODO: remove these prototypes and their users
539 #define android_testLog(prio, tag) (1)
540 #define android_writevLog(vec,num) do{}while(0)
541 #define android_write1Log(str,len) do{}while (0)
542 #define android_setMinPriority(tag, prio) do{}while(0)
543 //#define android_logToCallback(func) do{}while(0)
544 #define android_logToFile(tag, file) (0)
545 #define android_logToFd(tag, fd) (0)
547 typedef enum {
548 LOG_ID_MAIN = 0,
549 LOG_ID_RADIO = 1,
550 LOG_ID_EVENTS = 2,
551 LOG_ID_SYSTEM = 3,
553 LOG_ID_MAX
554 } log_id_t;
557 * Send a simple string to the log.
559 int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
560 int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
563 #ifdef __cplusplus
565 #endif
567 #endif // _LIBS_CUTILS_LOG_H