blob: 2997a0cee1077a83a20336eae193386b547ae0e3 [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 */
Steve Block8aeb6e22012-01-06 14:13:42 +0000174#ifndef ALOGE
175#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
176// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800177#ifndef LOGE
Steve Block8aeb6e22012-01-06 14:13:42 +0000178#define LOGE ALOGE
179#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800180#endif
181
Steve Block8aeb6e22012-01-06 14:13:42 +0000182#ifndef ALOGE_IF
183#define ALOGE_IF(cond, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800184 ( (CONDITION(cond)) \
Steve Block61fbcbe2011-10-12 17:22:43 +0100185 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800186 : (void)0 )
Steve Block8aeb6e22012-01-06 14:13:42 +0000187// Temporary measure for code still using old LOG macros.
188#ifndef LOGE_IF
189#define LOGE_IF ALOGE_IF
190#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800191#endif
192
193// ---------------------------------------------------------------------
194
195/*
196 * Conditional based on whether the current LOG_TAG is enabled at
197 * verbose priority.
198 */
Steve Block66b68752011-10-20 11:54:09 +0100199#ifndef IF_ALOGV
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800200#if LOG_NDEBUG
Steve Block66b68752011-10-20 11:54:09 +0100201#define IF_ALOGV() if (false)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800202#else
Steve Block66b68752011-10-20 11:54:09 +0100203#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800204#endif
Steve Block66b68752011-10-20 11:54:09 +0100205// Temporary measure for code still using old LOG macros.
206#ifndef IF_LOGV
207#define IF_LOGV IF_ALOGV
208#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800209#endif
210
211/*
212 * Conditional based on whether the current LOG_TAG is enabled at
213 * debug priority.
214 */
Steve Block9786ec42011-12-20 16:07:45 +0000215#ifndef IF_ALOGD
216#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
217// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800218#ifndef IF_LOGD
Steve Block9786ec42011-12-20 16:07:45 +0000219#define IF_LOGD IF_ALOGD
220#endif
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 * info priority.
226 */
Steve Block4163b452012-01-04 19:19:03 +0000227#ifndef IF_ALOGI
228#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
229// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800230#ifndef IF_LOGI
Steve Block4163b452012-01-04 19:19:03 +0000231#define IF_LOGI IF_ALOGI
232#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800233#endif
234
235/*
236 * Conditional based on whether the current LOG_TAG is enabled at
237 * warn priority.
238 */
Steve Block4f07a1f2012-01-05 22:25:38 +0000239#ifndef IF_ALOGW
240#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
241// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800242#ifndef IF_LOGW
Steve Block4f07a1f2012-01-05 22:25:38 +0000243#define IF_LOGW IF_ALOGW
244#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800245#endif
246
247/*
248 * Conditional based on whether the current LOG_TAG is enabled at
249 * error priority.
250 */
Steve Block8aeb6e22012-01-06 14:13:42 +0000251#ifndef IF_ALOGE
252#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
253// Temporary measure for code still using old LOG macros.
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800254#ifndef IF_LOGE
Steve Block8aeb6e22012-01-06 14:13:42 +0000255#define IF_LOGE IF_ALOGE
256#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800257#endif
258
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800259
260// ---------------------------------------------------------------------
261
262/*
263 * Simplified macro to send a verbose system log message using the current LOG_TAG.
264 */
265#ifndef SLOGV
266#if LOG_NDEBUG
267#define SLOGV(...) ((void)0)
268#else
269#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
270#endif
271#endif
272
273#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
274
275#ifndef SLOGV_IF
276#if LOG_NDEBUG
277#define SLOGV_IF(cond, ...) ((void)0)
278#else
279#define SLOGV_IF(cond, ...) \
280 ( (CONDITION(cond)) \
281 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
282 : (void)0 )
283#endif
284#endif
285
286/*
287 * Simplified macro to send a debug system log message using the current LOG_TAG.
288 */
289#ifndef SLOGD
290#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
291#endif
292
293#ifndef SLOGD_IF
294#define SLOGD_IF(cond, ...) \
295 ( (CONDITION(cond)) \
296 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
297 : (void)0 )
298#endif
299
300/*
301 * Simplified macro to send an info system log message using the current LOG_TAG.
302 */
303#ifndef SLOGI
304#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
305#endif
306
307#ifndef SLOGI_IF
308#define SLOGI_IF(cond, ...) \
309 ( (CONDITION(cond)) \
310 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
311 : (void)0 )
312#endif
313
314/*
315 * Simplified macro to send a warning system log message using the current LOG_TAG.
316 */
317#ifndef SLOGW
318#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
319#endif
320
321#ifndef SLOGW_IF
322#define SLOGW_IF(cond, ...) \
323 ( (CONDITION(cond)) \
324 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
325 : (void)0 )
326#endif
327
328/*
329 * Simplified macro to send an error system log message using the current LOG_TAG.
330 */
331#ifndef SLOGE
332#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
333#endif
334
335#ifndef SLOGE_IF
336#define SLOGE_IF(cond, ...) \
337 ( (CONDITION(cond)) \
338 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
339 : (void)0 )
340#endif
341
342
343
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800344// ---------------------------------------------------------------------
345
346/*
347 * Log a fatal error. If the given condition fails, this stops program
348 * execution like a normal assertion, but also generating the given message.
349 * It is NOT stripped from release builds. Note that the condition test
350 * is -inverted- from the normal assert() semantics.
351 */
Alexandre Elias412514e2011-03-29 16:24:45 -0700352#ifndef LOG_ALWAYS_FATAL_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800353#define LOG_ALWAYS_FATAL_IF(cond, ...) \
354 ( (CONDITION(cond)) \
Chris Pearson19299902010-06-02 16:25:35 -0700355 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800356 : (void)0 )
Alexandre Elias412514e2011-03-29 16:24:45 -0700357#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800358
Alexandre Elias412514e2011-03-29 16:24:45 -0700359#ifndef LOG_ALWAYS_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800360#define LOG_ALWAYS_FATAL(...) \
Chris Pearson19299902010-06-02 16:25:35 -0700361 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
Alexandre Elias412514e2011-03-29 16:24:45 -0700362#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800363
364/*
365 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
366 * are stripped out of release builds.
367 */
368#if LOG_NDEBUG
369
Alexandre Elias412514e2011-03-29 16:24:45 -0700370#ifndef LOG_FATAL_IF
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800371#define LOG_FATAL_IF(cond, ...) ((void)0)
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(...) ((void)0)
Alexandre Elias412514e2011-03-29 16:24:45 -0700375#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800376
377#else
378
Alexandre Elias412514e2011-03-29 16:24:45 -0700379#ifndef LOG_FATAL_IF
Chris Pearson19299902010-06-02 16:25:35 -0700380#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
Alexandre Elias412514e2011-03-29 16:24:45 -0700381#endif
382#ifndef LOG_FATAL
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800383#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
Alexandre Elias412514e2011-03-29 16:24:45 -0700384#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800385
386#endif
387
388/*
389 * Assertion that generates a log message when the assertion fails.
390 * Stripped out of release builds. Uses the current LOG_TAG.
391 */
Steve Block2ac29d02012-01-09 18:31:54 +0000392#ifndef ALOG_ASSERT
393#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
394//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
395// Temporary measure for code still using old LOG macros.
Alexandre Elias412514e2011-03-29 16:24:45 -0700396#ifndef LOG_ASSERT
Steve Block2ac29d02012-01-09 18:31:54 +0000397#define LOG_ASSERT ALOG_ASSERT
398#endif
Alexandre Elias412514e2011-03-29 16:24:45 -0700399#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800400
401// ---------------------------------------------------------------------
402
403/*
404 * Basic log message macro.
405 *
406 * Example:
Steve Block61fbcbe2011-10-12 17:22:43 +0100407 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800408 *
409 * The second argument may be NULL or "" to indicate the "global" tag.
410 */
Steve Block61fbcbe2011-10-12 17:22:43 +0100411#ifndef ALOG
412#define ALOG(priority, tag, ...) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800413 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
Steve Block61fbcbe2011-10-12 17:22:43 +0100414// Temporary measure for code still using old LOG macros.
415#ifndef LOG
416#define LOG ALOG
417#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800418#endif
419
420/*
421 * Log macro that allows you to specify a number for the priority.
422 */
423#ifndef LOG_PRI
424#define LOG_PRI(priority, tag, ...) \
425 android_printLog(priority, tag, __VA_ARGS__)
426#endif
427
428/*
429 * Log macro that allows you to pass in a varargs ("args" is a va_list).
430 */
431#ifndef LOG_PRI_VA
432#define LOG_PRI_VA(priority, tag, fmt, args) \
433 android_vprintLog(priority, NULL, tag, fmt, args)
434#endif
435
436/*
437 * Conditional given a desired logging priority and tag.
438 */
Steve Block61fbcbe2011-10-12 17:22:43 +0100439#ifndef IF_ALOG
440#define IF_ALOG(priority, tag) \
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800441 if (android_testLog(ANDROID_##priority, tag))
Steve Block61fbcbe2011-10-12 17:22:43 +0100442// Temporary measure for code still using old LOG macros.
443#ifndef IF_LOG
444#define IF_LOG IF_ALOG
445#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800446#endif
447
448// ---------------------------------------------------------------------
449
450/*
451 * Event logging.
452 */
453
454/*
455 * Event log entry types. These must match up with the declarations in
456 * java/android/android/util/EventLog.java.
457 */
458typedef enum {
459 EVENT_TYPE_INT = 0,
460 EVENT_TYPE_LONG = 1,
461 EVENT_TYPE_STRING = 2,
462 EVENT_TYPE_LIST = 3,
463} AndroidEventLogType;
464
465
Alexandre Elias412514e2011-03-29 16:24:45 -0700466#ifndef LOG_EVENT_INT
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800467#define LOG_EVENT_INT(_tag, _value) { \
468 int intBuf = _value; \
469 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
470 sizeof(intBuf)); \
471 }
Alexandre Elias412514e2011-03-29 16:24:45 -0700472#endif
473#ifndef LOG_EVENT_LONG
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800474#define LOG_EVENT_LONG(_tag, _value) { \
475 long long longBuf = _value; \
476 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
477 sizeof(longBuf)); \
478 }
Alexandre Elias412514e2011-03-29 16:24:45 -0700479#endif
480#ifndef LOG_EVENT_STRING
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800481#define LOG_EVENT_STRING(_tag, _value) \
482 ((void) 0) /* not implemented -- must combine len with string */
Alexandre Elias412514e2011-03-29 16:24:45 -0700483#endif
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800484/* TODO: something for LIST */
485
486/*
487 * ===========================================================================
488 *
489 * The stuff in the rest of this file should not be used directly.
490 */
491
492#define android_printLog(prio, tag, fmt...) \
493 __android_log_print(prio, tag, fmt)
494
495#define android_vprintLog(prio, cond, tag, fmt...) \
496 __android_log_vprint(prio, tag, fmt)
497
Chris Pearson19299902010-06-02 16:25:35 -0700498/* XXX Macros to work around syntax errors in places where format string
Steve Block2ac29d02012-01-09 18:31:54 +0000499 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
Chris Pearson19299902010-06-02 16:25:35 -0700500 * (happens only in debug builds).
501 */
502
503/* Returns 2nd arg. Used to substitute default value if caller's vararg list
504 * is empty.
505 */
506#define __android_second(dummy, second, ...) second
507
508/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
509 * returns nothing.
510 */
511#define __android_rest(first, ...) , ## __VA_ARGS__
512
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800513#define android_printAssert(cond, tag, fmt...) \
Chris Pearson19299902010-06-02 16:25:35 -0700514 __android_log_assert(cond, tag, \
515 __android_second(0, ## fmt, NULL) __android_rest(fmt))
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800516
517#define android_writeLog(prio, tag, text) \
518 __android_log_write(prio, tag, text)
519
520#define android_bWriteLog(tag, payload, len) \
521 __android_log_bwrite(tag, payload, len)
522#define android_btWriteLog(tag, type, payload, len) \
523 __android_log_btwrite(tag, type, payload, len)
Chris Pearson19299902010-06-02 16:25:35 -0700524
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800525// TODO: remove these prototypes and their users
526#define android_testLog(prio, tag) (1)
527#define android_writevLog(vec,num) do{}while(0)
528#define android_write1Log(str,len) do{}while (0)
529#define android_setMinPriority(tag, prio) do{}while(0)
530//#define android_logToCallback(func) do{}while(0)
531#define android_logToFile(tag, file) (0)
532#define android_logToFd(tag, fd) (0)
533
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800534typedef enum {
535 LOG_ID_MAIN = 0,
536 LOG_ID_RADIO = 1,
537 LOG_ID_EVENTS = 2,
538 LOG_ID_SYSTEM = 3,
539
540 LOG_ID_MAX
541} log_id_t;
542
543/*
544 * Send a simple string to the log.
545 */
546int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
547int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
548
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800549
550#ifdef __cplusplus
551}
552#endif
553
554#endif // _LIBS_CUTILS_LOG_H