blob: 4e6a57d43ee365e24542f1733c417698f1e6f41e [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 */
Steve Block4163b452012-01-04 19:19:03 +0000130#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 Projectdd7bc332009-03-03 19:32:55 -0800133#ifndef LOGI
Steve Block4163b452012-01-04 19:19:03 +0000134#define LOGI ALOGI
135#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800136#endif
137
Steve Block4163b452012-01-04 19:19:03 +0000138#ifndef ALOGI_IF
139#define ALOGI_IF(cond, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800140 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100141 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800142 : (void)0 )
Steve Block4163b452012-01-04 19:19:03 +0000143// 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 Projectdd7bc332009-03-03 19:32:55 -0800147#endif
148
149/*
150 * Simplified macro to send a warning log message using the current LOG_TAG.
151 */
Steve Block4f07a1f2012-01-05 22:25:38 +0000152#ifndef ALOGW
153#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
154// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800155#ifndef LOGW
Steve Block4f07a1f2012-01-05 22:25:38 +0000156#define LOGW ALOGW
157#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800158#endif
159
Steve Block4f07a1f2012-01-05 22:25:38 +0000160#ifndef ALOGW_IF
161#define ALOGW_IF(cond, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800162 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100163 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800164 : (void)0 )
Steve Block4f07a1f2012-01-05 22:25:38 +0000165// Temporary measure for code still using old LOG macros.
166#ifndef LOGW_IF
167#define LOGW_IF ALOGW_IF
168#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800169#endif
170
171/*
172 * Simplified macro to send an error log message using the current LOG_TAG.
173 */
174#ifndef LOGE
Steve Block61fbcbe2011-10-12 17:22:43 +0100175#define LOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
Steve Blocke7e7fac2011-12-22 15:00:35 +0000176#define ALOGE LOGE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800177#endif
178
179#ifndef LOGE_IF
180#define LOGE_IF(cond, ...) \
181 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100182 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800183 : (void)0 )
Steve Blocke7e7fac2011-12-22 15:00:35 +0000184#define ALOGE_IF LOGE_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800185#endif
186
187// ---------------------------------------------------------------------
188
189/*
190 * Conditional based on whether the current LOG_TAG is enabled at
191 * verbose priority.
192 */
Steve Block66b68752011-10-20 11:54:09 +0100193#ifndef IF_ALOGV
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800194#if LOG_NDEBUG
Steve Block66b68752011-10-20 11:54:09 +0100195#define IF_ALOGV() if (false)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800196#else
Steve Block66b68752011-10-20 11:54:09 +0100197#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800198#endif
Steve Block66b68752011-10-20 11:54:09 +0100199// Temporary measure for code still using old LOG macros.
200#ifndef IF_LOGV
201#define IF_LOGV IF_ALOGV
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 * debug priority.
208 */
Steve Block9786ec42011-12-20 16:07:45 +0000209#ifndef IF_ALOGD
210#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
211// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800212#ifndef IF_LOGD
Steve Block9786ec42011-12-20 16:07:45 +0000213#define IF_LOGD IF_ALOGD
214#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800215#endif
216
217/*
218 * Conditional based on whether the current LOG_TAG is enabled at
219 * info priority.
220 */
Steve Block4163b452012-01-04 19:19:03 +0000221#ifndef IF_ALOGI
222#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
223// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800224#ifndef IF_LOGI
Steve Block4163b452012-01-04 19:19:03 +0000225#define IF_LOGI IF_ALOGI
226#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800227#endif
228
229/*
230 * Conditional based on whether the current LOG_TAG is enabled at
231 * warn priority.
232 */
Steve Block4f07a1f2012-01-05 22:25:38 +0000233#ifndef IF_ALOGW
234#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
235// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800236#ifndef IF_LOGW
Steve Block4f07a1f2012-01-05 22:25:38 +0000237#define IF_LOGW IF_ALOGW
238#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800239#endif
240
241/*
242 * Conditional based on whether the current LOG_TAG is enabled at
243 * error priority.
244 */
245#ifndef IF_LOGE
Steve Block61fbcbe2011-10-12 17:22:43 +0100246#define IF_LOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
Steve Blocke7e7fac2011-12-22 15:00:35 +0000247#define IF_ALOGE IF_LOGE
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800248#endif
249
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800250
251// ---------------------------------------------------------------------
252
253/*
254 * Simplified macro to send a verbose system log message using the current LOG_TAG.
255 */
256#ifndef SLOGV
257#if LOG_NDEBUG
258#define SLOGV(...) ((void)0)
259#else
260#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
261#endif
262#endif
263
264#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
265
266#ifndef SLOGV_IF
267#if LOG_NDEBUG
268#define SLOGV_IF(cond, ...) ((void)0)
269#else
270#define SLOGV_IF(cond, ...) \
271 ( (CONDITION(cond)) \
272 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
273 : (void)0 )
274#endif
275#endif
276
277/*
278 * Simplified macro to send a debug system log message using the current LOG_TAG.
279 */
280#ifndef SLOGD
281#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
282#endif
283
284#ifndef SLOGD_IF
285#define SLOGD_IF(cond, ...) \
286 ( (CONDITION(cond)) \
287 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
288 : (void)0 )
289#endif
290
291/*
292 * Simplified macro to send an info system log message using the current LOG_TAG.
293 */
294#ifndef SLOGI
295#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
296#endif
297
298#ifndef SLOGI_IF
299#define SLOGI_IF(cond, ...) \
300 ( (CONDITION(cond)) \
301 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
302 : (void)0 )
303#endif
304
305/*
306 * Simplified macro to send a warning system log message using the current LOG_TAG.
307 */
308#ifndef SLOGW
309#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
310#endif
311
312#ifndef SLOGW_IF
313#define SLOGW_IF(cond, ...) \
314 ( (CONDITION(cond)) \
315 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
316 : (void)0 )
317#endif
318
319/*
320 * Simplified macro to send an error system log message using the current LOG_TAG.
321 */
322#ifndef SLOGE
323#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
324#endif
325
326#ifndef SLOGE_IF
327#define SLOGE_IF(cond, ...) \
328 ( (CONDITION(cond)) \
329 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
330 : (void)0 )
331#endif
332
333
334
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800335// ---------------------------------------------------------------------
336
337/*
338 * Log a fatal error. If the given condition fails, this stops program
339 * execution like a normal assertion, but also generating the given message.
340 * It is NOT stripped from release builds. Note that the condition test
341 * is -inverted- from the normal assert() semantics.
342 */
Alexandre Elias412514e2011-03-29 16:24:45 -0700343#ifndef LOG_ALWAYS_FATAL_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800344#define LOG_ALWAYS_FATAL_IF(cond, ...) \
345 ( (CONDITION(cond)) \
Chris Pearson19299902010-06-02 16:25:35 -0700346 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800347 : (void)0 )
Alexandre Elias412514e2011-03-29 16:24:45 -0700348#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800349
Alexandre Elias412514e2011-03-29 16:24:45 -0700350#ifndef LOG_ALWAYS_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800351#define LOG_ALWAYS_FATAL(...) \
Chris Pearson19299902010-06-02 16:25:35 -0700352 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
Alexandre Elias412514e2011-03-29 16:24:45 -0700353#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800354
355/*
356 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
357 * are stripped out of release builds.
358 */
359#if LOG_NDEBUG
360
Alexandre Elias412514e2011-03-29 16:24:45 -0700361#ifndef LOG_FATAL_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800362#define LOG_FATAL_IF(cond, ...) ((void)0)
Alexandre Elias412514e2011-03-29 16:24:45 -0700363#endif
364#ifndef LOG_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800365#define LOG_FATAL(...) ((void)0)
Alexandre Elias412514e2011-03-29 16:24:45 -0700366#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800367
368#else
369
Alexandre Elias412514e2011-03-29 16:24:45 -0700370#ifndef LOG_FATAL_IF
Chris Pearson19299902010-06-02 16:25:35 -0700371#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
Alexandre Elias412514e2011-03-29 16:24:45 -0700372#endif
373#ifndef LOG_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800374#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
Alexandre Elias412514e2011-03-29 16:24:45 -0700375#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800376
377#endif
378
379/*
380 * Assertion that generates a log message when the assertion fails.
381 * Stripped out of release builds. Uses the current LOG_TAG.
382 */
Alexandre Elias412514e2011-03-29 16:24:45 -0700383#ifndef LOG_ASSERT
Chris Pearson19299902010-06-02 16:25:35 -0700384#define LOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800385//#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
Steve Blocka9b84a72012-01-09 22:50:36 +0000386#define ALOG_ASSERT LOG_ASSERT
Alexandre Elias412514e2011-03-29 16:24:45 -0700387#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800388
389// ---------------------------------------------------------------------
390
391/*
392 * Basic log message macro.
393 *
394 * Example:
Steve Block61fbcbe2011-10-12 17:22:43 +0100395 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800396 *
397 * The second argument may be NULL or "" to indicate the "global" tag.
398 */
Steve Block61fbcbe2011-10-12 17:22:43 +0100399#ifndef ALOG
400#define ALOG(priority, tag, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800401 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
Steve Block61fbcbe2011-10-12 17:22:43 +0100402// Temporary measure for code still using old LOG macros.
403#ifndef LOG
404#define LOG ALOG
405#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800406#endif
407
408/*
409 * Log macro that allows you to specify a number for the priority.
410 */
411#ifndef LOG_PRI
412#define LOG_PRI(priority, tag, ...) \
413 android_printLog(priority, tag, __VA_ARGS__)
414#endif
415
416/*
417 * Log macro that allows you to pass in a varargs ("args" is a va_list).
418 */
419#ifndef LOG_PRI_VA
420#define LOG_PRI_VA(priority, tag, fmt, args) \
421 android_vprintLog(priority, NULL, tag, fmt, args)
422#endif
423
424/*
425 * Conditional given a desired logging priority and tag.
426 */
Steve Block61fbcbe2011-10-12 17:22:43 +0100427#ifndef IF_ALOG
428#define IF_ALOG(priority, tag) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800429 if (android_testLog(ANDROID_##priority, tag))
Steve Block61fbcbe2011-10-12 17:22:43 +0100430// Temporary measure for code still using old LOG macros.
431#ifndef IF_LOG
432#define IF_LOG IF_ALOG
433#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800434#endif
435
436// ---------------------------------------------------------------------
437
438/*
439 * Event logging.
440 */
441
442/*
443 * Event log entry types. These must match up with the declarations in
444 * java/android/android/util/EventLog.java.
445 */
446typedef enum {
447 EVENT_TYPE_INT = 0,
448 EVENT_TYPE_LONG = 1,
449 EVENT_TYPE_STRING = 2,
450 EVENT_TYPE_LIST = 3,
451} AndroidEventLogType;
452
453
Alexandre Elias412514e2011-03-29 16:24:45 -0700454#ifndef LOG_EVENT_INT
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800455#define LOG_EVENT_INT(_tag, _value) { \
456 int intBuf = _value; \
457 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
458 sizeof(intBuf)); \
459 }
Alexandre Elias412514e2011-03-29 16:24:45 -0700460#endif
461#ifndef LOG_EVENT_LONG
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800462#define LOG_EVENT_LONG(_tag, _value) { \
463 long long longBuf = _value; \
464 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
465 sizeof(longBuf)); \
466 }
Alexandre Elias412514e2011-03-29 16:24:45 -0700467#endif
468#ifndef LOG_EVENT_STRING
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800469#define LOG_EVENT_STRING(_tag, _value) \
470 ((void) 0) /* not implemented -- must combine len with string */
Alexandre Elias412514e2011-03-29 16:24:45 -0700471#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800472/* TODO: something for LIST */
473
474/*
475 * ===========================================================================
476 *
477 * The stuff in the rest of this file should not be used directly.
478 */
479
480#define android_printLog(prio, tag, fmt...) \
481 __android_log_print(prio, tag, fmt)
482
483#define android_vprintLog(prio, cond, tag, fmt...) \
484 __android_log_vprint(prio, tag, fmt)
485
Chris Pearson19299902010-06-02 16:25:35 -0700486/* XXX Macros to work around syntax errors in places where format string
487 * arg is not passed to LOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
488 * (happens only in debug builds).
489 */
490
491/* Returns 2nd arg. Used to substitute default value if caller's vararg list
492 * is empty.
493 */
494#define __android_second(dummy, second, ...) second
495
496/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
497 * returns nothing.
498 */
499#define __android_rest(first, ...) , ## __VA_ARGS__
500
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800501#define android_printAssert(cond, tag, fmt...) \
Chris Pearson19299902010-06-02 16:25:35 -0700502 __android_log_assert(cond, tag, \
503 __android_second(0, ## fmt, NULL) __android_rest(fmt))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800504
505#define android_writeLog(prio, tag, text) \
506 __android_log_write(prio, tag, text)
507
508#define android_bWriteLog(tag, payload, len) \
509 __android_log_bwrite(tag, payload, len)
510#define android_btWriteLog(tag, type, payload, len) \
511 __android_log_btwrite(tag, type, payload, len)
Chris Pearson19299902010-06-02 16:25:35 -0700512
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800513// TODO: remove these prototypes and their users
514#define android_testLog(prio, tag) (1)
515#define android_writevLog(vec,num) do{}while(0)
516#define android_write1Log(str,len) do{}while (0)
517#define android_setMinPriority(tag, prio) do{}while(0)
518//#define android_logToCallback(func) do{}while(0)
519#define android_logToFile(tag, file) (0)
520#define android_logToFd(tag, fd) (0)
521
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800522typedef enum {
523 LOG_ID_MAIN = 0,
524 LOG_ID_RADIO = 1,
525 LOG_ID_EVENTS = 2,
526 LOG_ID_SYSTEM = 3,
527
528 LOG_ID_MAX
529} log_id_t;
530
531/*
532 * Send a simple string to the log.
533 */
534int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
535int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
536
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800537
538#ifdef __cplusplus
539}
540#endif
541
542#endif // _LIBS_CUTILS_LOG_H