blob: 121e350f521b809400630c2f39a50a96b39dcc6d [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
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
44extern "C" {
45#endif
46
47// ---------------------------------------------------------------------
48
49/*
Steve Block66b68752011-10-20 11:54:09 +010050 * Normally we strip ALOGV (VERBOSE messages) from release builds.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080051 * 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 Block66b68752011-10-20 11:54:09 +010076#ifndef ALOGV
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080077#if LOG_NDEBUG
Steve Block66b68752011-10-20 11:54:09 +010078#define ALOGV(...) ((void)0)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080079#else
Steve Block66b68752011-10-20 11:54:09 +010080#define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080081#endif
Steve Block66b68752011-10-20 11:54:09 +010082// Temporary measure for code still using old LOG macros.
83#ifndef LOGV
84#define LOGV ALOGV
85#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080086#endif
87
88#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
89
Steve Block66b68752011-10-20 11:54:09 +010090#ifndef ALOGV_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080091#if LOG_NDEBUG
Steve Block66b68752011-10-20 11:54:09 +010092#define ALOGV_IF(cond, ...) ((void)0)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080093#else
Steve Block66b68752011-10-20 11:54:09 +010094#define ALOGV_IF(cond, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080095 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +010096 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080097 : (void)0 )
98#endif
Steve Block66b68752011-10-20 11:54:09 +010099// 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 Projectdd7bc332009-03-03 19:32:55 -0800103#endif
104
105/*
106 * Simplified macro to send a debug log message using the current LOG_TAG.
107 */
Steve Block9786ec42011-12-20 16:07:45 +0000108#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 Projectdd7bc332009-03-03 19:32:55 -0800111#ifndef LOGD
Steve Block9786ec42011-12-20 16:07:45 +0000112#define LOGD ALOGD
113#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800114#endif
115
Steve Block9786ec42011-12-20 16:07:45 +0000116#ifndef ALOGD_IF
117#define ALOGD_IF(cond, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800118 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100119 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800120 : (void)0 )
Steve Block9786ec42011-12-20 16:07:45 +0000121// 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 Projectdd7bc332009-03-03 19:32:55 -0800125#endif
126
127/*
128 * Simplified macro to send an info log message using the current LOG_TAG.
129 */
130#ifndef LOGI
Steve Block61fbcbe2011-10-12 17:22:43 +0100131#define LOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
Steve Blocke7e7fac2011-12-22 15:00:35 +0000132#define ALOGI LOGI
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800133#endif
134
135#ifndef LOGI_IF
136#define LOGI_IF(cond, ...) \
137 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100138 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800139 : (void)0 )
Steve Blocke7e7fac2011-12-22 15:00:35 +0000140#define ALOGI_IF LOGI_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800141#endif
142
143/*
144 * Simplified macro to send a warning log message using the current LOG_TAG.
145 */
146#ifndef LOGW
Steve Block61fbcbe2011-10-12 17:22:43 +0100147#define LOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
Steve Blocke7e7fac2011-12-22 15:00:35 +0000148#define ALOGW LOGW
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800149#endif
150
151#ifndef LOGW_IF
152#define LOGW_IF(cond, ...) \
153 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100154 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800155 : (void)0 )
Steve Blocke7e7fac2011-12-22 15:00:35 +0000156#define ALOGW_IF LOGW_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800157#endif
158
159/*
160 * Simplified macro to send an error log message using the current LOG_TAG.
161 */
162#ifndef LOGE
Steve Block61fbcbe2011-10-12 17:22:43 +0100163#define LOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
Steve Blocke7e7fac2011-12-22 15:00:35 +0000164#define ALOGE LOGE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800165#endif
166
167#ifndef LOGE_IF
168#define LOGE_IF(cond, ...) \
169 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100170 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800171 : (void)0 )
Steve Blocke7e7fac2011-12-22 15:00:35 +0000172#define ALOGE_IF LOGE_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800173#endif
174
175// ---------------------------------------------------------------------
176
177/*
178 * Conditional based on whether the current LOG_TAG is enabled at
179 * verbose priority.
180 */
Steve Block66b68752011-10-20 11:54:09 +0100181#ifndef IF_ALOGV
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800182#if LOG_NDEBUG
Steve Block66b68752011-10-20 11:54:09 +0100183#define IF_ALOGV() if (false)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800184#else
Steve Block66b68752011-10-20 11:54:09 +0100185#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800186#endif
Steve Block66b68752011-10-20 11:54:09 +0100187// Temporary measure for code still using old LOG macros.
188#ifndef IF_LOGV
189#define IF_LOGV IF_ALOGV
190#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800191#endif
192
193/*
194 * Conditional based on whether the current LOG_TAG is enabled at
195 * debug priority.
196 */
Steve Block9786ec42011-12-20 16:07:45 +0000197#ifndef IF_ALOGD
198#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
199// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800200#ifndef IF_LOGD
Steve Block9786ec42011-12-20 16:07:45 +0000201#define IF_LOGD IF_ALOGD
202#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800203#endif
204
205/*
206 * Conditional based on whether the current LOG_TAG is enabled at
207 * info priority.
208 */
209#ifndef IF_LOGI
Steve Block61fbcbe2011-10-12 17:22:43 +0100210#define IF_LOGI() IF_ALOG(LOG_INFO, LOG_TAG)
Steve Blocke7e7fac2011-12-22 15:00:35 +0000211#define IF_ALOGI IF_LOGI
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800212#endif
213
214/*
215 * Conditional based on whether the current LOG_TAG is enabled at
216 * warn priority.
217 */
218#ifndef IF_LOGW
Steve Block61fbcbe2011-10-12 17:22:43 +0100219#define IF_LOGW() IF_ALOG(LOG_WARN, LOG_TAG)
Steve Blocke7e7fac2011-12-22 15:00:35 +0000220#define IF_ALOGW IF_LOGW
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800221#endif
222
223/*
224 * Conditional based on whether the current LOG_TAG is enabled at
225 * error priority.
226 */
227#ifndef IF_LOGE
Steve Block61fbcbe2011-10-12 17:22:43 +0100228#define IF_LOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
Steve Blocke7e7fac2011-12-22 15:00:35 +0000229#define IF_ALOGE IF_LOGE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800230#endif
231
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800232
233// ---------------------------------------------------------------------
234
235/*
236 * Simplified macro to send a verbose system log message using the current LOG_TAG.
237 */
238#ifndef SLOGV
239#if LOG_NDEBUG
240#define SLOGV(...) ((void)0)
241#else
242#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
243#endif
244#endif
245
246#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
247
248#ifndef SLOGV_IF
249#if LOG_NDEBUG
250#define SLOGV_IF(cond, ...) ((void)0)
251#else
252#define SLOGV_IF(cond, ...) \
253 ( (CONDITION(cond)) \
254 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
255 : (void)0 )
256#endif
257#endif
258
259/*
260 * Simplified macro to send a debug system log message using the current LOG_TAG.
261 */
262#ifndef SLOGD
263#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
264#endif
265
266#ifndef SLOGD_IF
267#define SLOGD_IF(cond, ...) \
268 ( (CONDITION(cond)) \
269 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
270 : (void)0 )
271#endif
272
273/*
274 * Simplified macro to send an info system log message using the current LOG_TAG.
275 */
276#ifndef SLOGI
277#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
278#endif
279
280#ifndef SLOGI_IF
281#define SLOGI_IF(cond, ...) \
282 ( (CONDITION(cond)) \
283 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
284 : (void)0 )
285#endif
286
287/*
288 * Simplified macro to send a warning system log message using the current LOG_TAG.
289 */
290#ifndef SLOGW
291#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
292#endif
293
294#ifndef SLOGW_IF
295#define SLOGW_IF(cond, ...) \
296 ( (CONDITION(cond)) \
297 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
298 : (void)0 )
299#endif
300
301/*
302 * Simplified macro to send an error system log message using the current LOG_TAG.
303 */
304#ifndef SLOGE
305#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
306#endif
307
308#ifndef SLOGE_IF
309#define SLOGE_IF(cond, ...) \
310 ( (CONDITION(cond)) \
311 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
312 : (void)0 )
313#endif
314
315
316
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800317// ---------------------------------------------------------------------
318
319/*
320 * Log a fatal error. If the given condition fails, this stops program
321 * execution like a normal assertion, but also generating the given message.
322 * It is NOT stripped from release builds. Note that the condition test
323 * is -inverted- from the normal assert() semantics.
324 */
Alexandre Elias412514e2011-03-29 16:24:45 -0700325#ifndef LOG_ALWAYS_FATAL_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800326#define LOG_ALWAYS_FATAL_IF(cond, ...) \
327 ( (CONDITION(cond)) \
Chris Pearson19299902010-06-02 16:25:35 -0700328 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800329 : (void)0 )
Alexandre Elias412514e2011-03-29 16:24:45 -0700330#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800331
Alexandre Elias412514e2011-03-29 16:24:45 -0700332#ifndef LOG_ALWAYS_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800333#define LOG_ALWAYS_FATAL(...) \
Chris Pearson19299902010-06-02 16:25:35 -0700334 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
Alexandre Elias412514e2011-03-29 16:24:45 -0700335#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800336
337/*
338 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
339 * are stripped out of release builds.
340 */
341#if LOG_NDEBUG
342
Alexandre Elias412514e2011-03-29 16:24:45 -0700343#ifndef LOG_FATAL_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800344#define LOG_FATAL_IF(cond, ...) ((void)0)
Alexandre Elias412514e2011-03-29 16:24:45 -0700345#endif
346#ifndef LOG_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800347#define LOG_FATAL(...) ((void)0)
Alexandre Elias412514e2011-03-29 16:24:45 -0700348#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800349
350#else
351
Alexandre Elias412514e2011-03-29 16:24:45 -0700352#ifndef LOG_FATAL_IF
Chris Pearson19299902010-06-02 16:25:35 -0700353#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
Alexandre Elias412514e2011-03-29 16:24:45 -0700354#endif
355#ifndef LOG_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800356#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
Alexandre Elias412514e2011-03-29 16:24:45 -0700357#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800358
359#endif
360
361/*
362 * Assertion that generates a log message when the assertion fails.
363 * Stripped out of release builds. Uses the current LOG_TAG.
364 */
Alexandre Elias412514e2011-03-29 16:24:45 -0700365#ifndef LOG_ASSERT
Chris Pearson19299902010-06-02 16:25:35 -0700366#define LOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800367//#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
Steve Blocka9b84a72012-01-09 22:50:36 +0000368#define ALOG_ASSERT LOG_ASSERT
Alexandre Elias412514e2011-03-29 16:24:45 -0700369#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800370
371// ---------------------------------------------------------------------
372
373/*
374 * Basic log message macro.
375 *
376 * Example:
Steve Block61fbcbe2011-10-12 17:22:43 +0100377 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800378 *
379 * The second argument may be NULL or "" to indicate the "global" tag.
380 */
Steve Block61fbcbe2011-10-12 17:22:43 +0100381#ifndef ALOG
382#define ALOG(priority, tag, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800383 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
Steve Block61fbcbe2011-10-12 17:22:43 +0100384// Temporary measure for code still using old LOG macros.
385#ifndef LOG
386#define LOG ALOG
387#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800388#endif
389
390/*
391 * Log macro that allows you to specify a number for the priority.
392 */
393#ifndef LOG_PRI
394#define LOG_PRI(priority, tag, ...) \
395 android_printLog(priority, tag, __VA_ARGS__)
396#endif
397
398/*
399 * Log macro that allows you to pass in a varargs ("args" is a va_list).
400 */
401#ifndef LOG_PRI_VA
402#define LOG_PRI_VA(priority, tag, fmt, args) \
403 android_vprintLog(priority, NULL, tag, fmt, args)
404#endif
405
406/*
407 * Conditional given a desired logging priority and tag.
408 */
Steve Block61fbcbe2011-10-12 17:22:43 +0100409#ifndef IF_ALOG
410#define IF_ALOG(priority, tag) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800411 if (android_testLog(ANDROID_##priority, tag))
Steve Block61fbcbe2011-10-12 17:22:43 +0100412// Temporary measure for code still using old LOG macros.
413#ifndef IF_LOG
414#define IF_LOG IF_ALOG
415#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800416#endif
417
418// ---------------------------------------------------------------------
419
420/*
421 * Event logging.
422 */
423
424/*
425 * Event log entry types. These must match up with the declarations in
426 * java/android/android/util/EventLog.java.
427 */
428typedef enum {
429 EVENT_TYPE_INT = 0,
430 EVENT_TYPE_LONG = 1,
431 EVENT_TYPE_STRING = 2,
432 EVENT_TYPE_LIST = 3,
433} AndroidEventLogType;
434
435
Alexandre Elias412514e2011-03-29 16:24:45 -0700436#ifndef LOG_EVENT_INT
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800437#define LOG_EVENT_INT(_tag, _value) { \
438 int intBuf = _value; \
439 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
440 sizeof(intBuf)); \
441 }
Alexandre Elias412514e2011-03-29 16:24:45 -0700442#endif
443#ifndef LOG_EVENT_LONG
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800444#define LOG_EVENT_LONG(_tag, _value) { \
445 long long longBuf = _value; \
446 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
447 sizeof(longBuf)); \
448 }
Alexandre Elias412514e2011-03-29 16:24:45 -0700449#endif
450#ifndef LOG_EVENT_STRING
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800451#define LOG_EVENT_STRING(_tag, _value) \
452 ((void) 0) /* not implemented -- must combine len with string */
Alexandre Elias412514e2011-03-29 16:24:45 -0700453#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800454/* TODO: something for LIST */
455
456/*
457 * ===========================================================================
458 *
459 * The stuff in the rest of this file should not be used directly.
460 */
461
462#define android_printLog(prio, tag, fmt...) \
463 __android_log_print(prio, tag, fmt)
464
465#define android_vprintLog(prio, cond, tag, fmt...) \
466 __android_log_vprint(prio, tag, fmt)
467
Chris Pearson19299902010-06-02 16:25:35 -0700468/* XXX Macros to work around syntax errors in places where format string
469 * arg is not passed to LOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
470 * (happens only in debug builds).
471 */
472
473/* Returns 2nd arg. Used to substitute default value if caller's vararg list
474 * is empty.
475 */
476#define __android_second(dummy, second, ...) second
477
478/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
479 * returns nothing.
480 */
481#define __android_rest(first, ...) , ## __VA_ARGS__
482
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800483#define android_printAssert(cond, tag, fmt...) \
Chris Pearson19299902010-06-02 16:25:35 -0700484 __android_log_assert(cond, tag, \
485 __android_second(0, ## fmt, NULL) __android_rest(fmt))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800486
487#define android_writeLog(prio, tag, text) \
488 __android_log_write(prio, tag, text)
489
490#define android_bWriteLog(tag, payload, len) \
491 __android_log_bwrite(tag, payload, len)
492#define android_btWriteLog(tag, type, payload, len) \
493 __android_log_btwrite(tag, type, payload, len)
Chris Pearson19299902010-06-02 16:25:35 -0700494
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800495// TODO: remove these prototypes and their users
496#define android_testLog(prio, tag) (1)
497#define android_writevLog(vec,num) do{}while(0)
498#define android_write1Log(str,len) do{}while (0)
499#define android_setMinPriority(tag, prio) do{}while(0)
500//#define android_logToCallback(func) do{}while(0)
501#define android_logToFile(tag, file) (0)
502#define android_logToFd(tag, fd) (0)
503
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800504typedef enum {
505 LOG_ID_MAIN = 0,
506 LOG_ID_RADIO = 1,
507 LOG_ID_EVENTS = 2,
508 LOG_ID_SYSTEM = 3,
509
510 LOG_ID_MAX
511} log_id_t;
512
513/*
514 * Send a simple string to the log.
515 */
516int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
517int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
518
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800519
520#ifdef __cplusplus
521}
522#endif
523
524#endif // _LIBS_CUTILS_LOG_H