blob: 9e53d7a2d8d42fa87d618e4ab671686cccc4610d [file] [log] [blame]
Colin Cross9227bd32013-07-23 16:59:20 -07001/*
Mark Salyzyn819c58a2013-11-22 12:39:43 -08002 * Copyright (C) 2005-2014 The Android Open Source Project
Colin Cross9227bd32013-07-23 16:59:20 -07003 *
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_LOG_LOG_H
29#define _LIBS_LOG_LOG_H
30
Colin Cross9227bd32013-07-23 16:59:20 -070031#include <stdarg.h>
Mark Salyzyn42958412013-11-22 10:50:27 -080032#include <stdio.h>
Yabin Cui4a6e5a32015-01-26 19:48:54 -080033#include <sys/types.h>
Mark Salyzyn42958412013-11-22 10:50:27 -080034#include <time.h>
35#include <unistd.h>
Yabin Cui4a6e5a32015-01-26 19:48:54 -080036
Colin Cross9227bd32013-07-23 16:59:20 -070037#include <log/logd.h>
Mark Salyzyn42958412013-11-22 10:50:27 -080038#include <log/uio.h>
Colin Cross9227bd32013-07-23 16:59:20 -070039
Mark Salyzynf387fa52014-01-03 16:54:28 -080040#ifdef __cplusplus
41extern "C" {
42#endif
Colin Cross9227bd32013-07-23 16:59:20 -070043
44// ---------------------------------------------------------------------
45
46/*
47 * Normally we strip ALOGV (VERBOSE messages) from release builds.
48 * You can modify this (for example with "#define LOG_NDEBUG 0"
49 * at the top of your source file) to change that behavior.
50 */
51#ifndef LOG_NDEBUG
52#ifdef NDEBUG
53#define LOG_NDEBUG 1
54#else
55#define LOG_NDEBUG 0
56#endif
57#endif
58
59/*
60 * This is the local tag used for the following simplified
61 * logging macros. You can change this preprocessor definition
62 * before using the other macros to change the tag.
63 */
64#ifndef LOG_TAG
65#define LOG_TAG NULL
66#endif
67
68// ---------------------------------------------------------------------
69
70/*
71 * Simplified macro to send a verbose log message using the current LOG_TAG.
72 */
73#ifndef ALOGV
Colin Cross810d19f2014-02-06 20:07:50 -080074#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -070075#if LOG_NDEBUG
Colin Cross810d19f2014-02-06 20:07:50 -080076#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
Colin Cross9227bd32013-07-23 16:59:20 -070077#else
Colin Cross810d19f2014-02-06 20:07:50 -080078#define ALOGV(...) __ALOGV(__VA_ARGS__)
Colin Cross9227bd32013-07-23 16:59:20 -070079#endif
80#endif
81
Mark Salyzynf5af82e2014-10-08 07:47:08 -070082#ifndef __predict_false
83#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
84#endif
Colin Cross9227bd32013-07-23 16:59:20 -070085
86#ifndef ALOGV_IF
87#if LOG_NDEBUG
88#define ALOGV_IF(cond, ...) ((void)0)
89#else
90#define ALOGV_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -070091 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -070092 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
93 : (void)0 )
94#endif
95#endif
96
97/*
98 * Simplified macro to send a debug log message using the current LOG_TAG.
99 */
100#ifndef ALOGD
101#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
102#endif
103
104#ifndef ALOGD_IF
105#define ALOGD_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700106 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700107 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
108 : (void)0 )
109#endif
110
111/*
112 * Simplified macro to send an info log message using the current LOG_TAG.
113 */
114#ifndef ALOGI
115#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
116#endif
117
118#ifndef ALOGI_IF
119#define ALOGI_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700120 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700121 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
122 : (void)0 )
123#endif
124
125/*
126 * Simplified macro to send a warning log message using the current LOG_TAG.
127 */
128#ifndef ALOGW
129#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
130#endif
131
132#ifndef ALOGW_IF
133#define ALOGW_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700134 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700135 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
136 : (void)0 )
137#endif
138
139/*
140 * Simplified macro to send an error log message using the current LOG_TAG.
141 */
142#ifndef ALOGE
143#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
144#endif
145
146#ifndef ALOGE_IF
147#define ALOGE_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700148 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700149 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
150 : (void)0 )
151#endif
152
153// ---------------------------------------------------------------------
154
155/*
156 * Conditional based on whether the current LOG_TAG is enabled at
157 * verbose priority.
158 */
159#ifndef IF_ALOGV
160#if LOG_NDEBUG
161#define IF_ALOGV() if (false)
162#else
163#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
164#endif
165#endif
166
167/*
168 * Conditional based on whether the current LOG_TAG is enabled at
169 * debug priority.
170 */
171#ifndef IF_ALOGD
172#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
173#endif
174
175/*
176 * Conditional based on whether the current LOG_TAG is enabled at
177 * info priority.
178 */
179#ifndef IF_ALOGI
180#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
181#endif
182
183/*
184 * Conditional based on whether the current LOG_TAG is enabled at
185 * warn priority.
186 */
187#ifndef IF_ALOGW
188#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
189#endif
190
191/*
192 * Conditional based on whether the current LOG_TAG is enabled at
193 * error priority.
194 */
195#ifndef IF_ALOGE
196#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
197#endif
198
199
200// ---------------------------------------------------------------------
201
202/*
203 * Simplified macro to send a verbose system log message using the current LOG_TAG.
204 */
205#ifndef SLOGV
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700206#define __SLOGV(...) \
207 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700208#if LOG_NDEBUG
Colin Cross810d19f2014-02-06 20:07:50 -0800209#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
Colin Cross9227bd32013-07-23 16:59:20 -0700210#else
Colin Cross810d19f2014-02-06 20:07:50 -0800211#define SLOGV(...) __SLOGV(__VA_ARGS__)
Colin Cross9227bd32013-07-23 16:59:20 -0700212#endif
213#endif
214
Colin Cross9227bd32013-07-23 16:59:20 -0700215#ifndef SLOGV_IF
216#if LOG_NDEBUG
217#define SLOGV_IF(cond, ...) ((void)0)
218#else
219#define SLOGV_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700220 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700221 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
222 : (void)0 )
223#endif
224#endif
225
226/*
227 * Simplified macro to send a debug system log message using the current LOG_TAG.
228 */
229#ifndef SLOGD
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700230#define SLOGD(...) \
231 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700232#endif
233
234#ifndef SLOGD_IF
235#define SLOGD_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700236 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700237 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
238 : (void)0 )
239#endif
240
241/*
242 * Simplified macro to send an info system log message using the current LOG_TAG.
243 */
244#ifndef SLOGI
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700245#define SLOGI(...) \
246 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700247#endif
248
249#ifndef SLOGI_IF
250#define SLOGI_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700251 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700252 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
253 : (void)0 )
254#endif
255
256/*
257 * Simplified macro to send a warning system log message using the current LOG_TAG.
258 */
259#ifndef SLOGW
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700260#define SLOGW(...) \
261 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700262#endif
263
264#ifndef SLOGW_IF
265#define SLOGW_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700266 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700267 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
268 : (void)0 )
269#endif
270
271/*
272 * Simplified macro to send an error system log message using the current LOG_TAG.
273 */
274#ifndef SLOGE
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700275#define SLOGE(...) \
276 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700277#endif
278
279#ifndef SLOGE_IF
280#define SLOGE_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700281 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700282 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
283 : (void)0 )
284#endif
285
286// ---------------------------------------------------------------------
287
288/*
289 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
290 */
291#ifndef RLOGV
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700292#define __RLOGV(...) \
293 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700294#if LOG_NDEBUG
Colin Cross810d19f2014-02-06 20:07:50 -0800295#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
Colin Cross9227bd32013-07-23 16:59:20 -0700296#else
Colin Cross810d19f2014-02-06 20:07:50 -0800297#define RLOGV(...) __RLOGV(__VA_ARGS__)
Colin Cross9227bd32013-07-23 16:59:20 -0700298#endif
299#endif
300
Colin Cross9227bd32013-07-23 16:59:20 -0700301#ifndef RLOGV_IF
302#if LOG_NDEBUG
303#define RLOGV_IF(cond, ...) ((void)0)
304#else
305#define RLOGV_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700306 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700307 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
308 : (void)0 )
309#endif
310#endif
311
312/*
313 * Simplified macro to send a debug radio log message using the current LOG_TAG.
314 */
315#ifndef RLOGD
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700316#define RLOGD(...) \
317 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700318#endif
319
320#ifndef RLOGD_IF
321#define RLOGD_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700322 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700323 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
324 : (void)0 )
325#endif
326
327/*
328 * Simplified macro to send an info radio log message using the current LOG_TAG.
329 */
330#ifndef RLOGI
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700331#define RLOGI(...) \
332 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700333#endif
334
335#ifndef RLOGI_IF
336#define RLOGI_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700337 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700338 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
339 : (void)0 )
340#endif
341
342/*
343 * Simplified macro to send a warning radio log message using the current LOG_TAG.
344 */
345#ifndef RLOGW
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700346#define RLOGW(...) \
347 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700348#endif
349
350#ifndef RLOGW_IF
351#define RLOGW_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700352 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700353 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
354 : (void)0 )
355#endif
356
357/*
358 * Simplified macro to send an error radio log message using the current LOG_TAG.
359 */
360#ifndef RLOGE
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700361#define RLOGE(...) \
362 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700363#endif
364
365#ifndef RLOGE_IF
366#define RLOGE_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700367 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700368 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
369 : (void)0 )
370#endif
371
372
373// ---------------------------------------------------------------------
374
375/*
376 * Log a fatal error. If the given condition fails, this stops program
377 * execution like a normal assertion, but also generating the given message.
378 * It is NOT stripped from release builds. Note that the condition test
379 * is -inverted- from the normal assert() semantics.
380 */
381#ifndef LOG_ALWAYS_FATAL_IF
382#define LOG_ALWAYS_FATAL_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700383 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700384 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
385 : (void)0 )
386#endif
387
388#ifndef LOG_ALWAYS_FATAL
389#define LOG_ALWAYS_FATAL(...) \
390 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
391#endif
392
393/*
394 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
395 * are stripped out of release builds.
396 */
397#if LOG_NDEBUG
398
399#ifndef LOG_FATAL_IF
400#define LOG_FATAL_IF(cond, ...) ((void)0)
401#endif
402#ifndef LOG_FATAL
403#define LOG_FATAL(...) ((void)0)
404#endif
405
406#else
407
408#ifndef LOG_FATAL_IF
409#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
410#endif
411#ifndef LOG_FATAL
412#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
413#endif
414
415#endif
416
417/*
418 * Assertion that generates a log message when the assertion fails.
419 * Stripped out of release builds. Uses the current LOG_TAG.
420 */
421#ifndef ALOG_ASSERT
422#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
423//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
424#endif
425
426// ---------------------------------------------------------------------
427
428/*
429 * Basic log message macro.
430 *
431 * Example:
432 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
433 *
434 * The second argument may be NULL or "" to indicate the "global" tag.
435 */
436#ifndef ALOG
437#define ALOG(priority, tag, ...) \
438 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
439#endif
440
441/*
442 * Log macro that allows you to specify a number for the priority.
443 */
444#ifndef LOG_PRI
445#define LOG_PRI(priority, tag, ...) \
446 android_printLog(priority, tag, __VA_ARGS__)
447#endif
448
449/*
450 * Log macro that allows you to pass in a varargs ("args" is a va_list).
451 */
452#ifndef LOG_PRI_VA
453#define LOG_PRI_VA(priority, tag, fmt, args) \
454 android_vprintLog(priority, NULL, tag, fmt, args)
455#endif
456
457/*
458 * Conditional given a desired logging priority and tag.
459 */
460#ifndef IF_ALOG
461#define IF_ALOG(priority, tag) \
462 if (android_testLog(ANDROID_##priority, tag))
463#endif
464
465// ---------------------------------------------------------------------
466
467/*
468 * Event logging.
469 */
470
471/*
472 * Event log entry types. These must match up with the declarations in
473 * java/android/android/util/EventLog.java.
474 */
475typedef enum {
476 EVENT_TYPE_INT = 0,
477 EVENT_TYPE_LONG = 1,
478 EVENT_TYPE_STRING = 2,
479 EVENT_TYPE_LIST = 3,
480} AndroidEventLogType;
Mark Salyzyn42958412013-11-22 10:50:27 -0800481#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
482#define typeof_AndroidEventLogType unsigned char
Colin Cross9227bd32013-07-23 16:59:20 -0700483
484#ifndef LOG_EVENT_INT
485#define LOG_EVENT_INT(_tag, _value) { \
486 int intBuf = _value; \
487 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
488 sizeof(intBuf)); \
489 }
490#endif
491#ifndef LOG_EVENT_LONG
492#define LOG_EVENT_LONG(_tag, _value) { \
493 long long longBuf = _value; \
494 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
495 sizeof(longBuf)); \
496 }
497#endif
498#ifndef LOG_EVENT_STRING
499#define LOG_EVENT_STRING(_tag, _value) \
Nick Kralevich2a4d05a2014-07-01 10:57:16 -0700500 (void) __android_log_bswrite(_tag, _value);
Colin Cross9227bd32013-07-23 16:59:20 -0700501#endif
502/* TODO: something for LIST */
503
504/*
505 * ===========================================================================
506 *
507 * The stuff in the rest of this file should not be used directly.
508 */
509
510#define android_printLog(prio, tag, fmt...) \
511 __android_log_print(prio, tag, fmt)
512
513#define android_vprintLog(prio, cond, tag, fmt...) \
514 __android_log_vprint(prio, tag, fmt)
515
516/* XXX Macros to work around syntax errors in places where format string
517 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
518 * (happens only in debug builds).
519 */
520
521/* Returns 2nd arg. Used to substitute default value if caller's vararg list
522 * is empty.
523 */
524#define __android_second(dummy, second, ...) second
525
526/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
527 * returns nothing.
528 */
529#define __android_rest(first, ...) , ## __VA_ARGS__
530
531#define android_printAssert(cond, tag, fmt...) \
532 __android_log_assert(cond, tag, \
533 __android_second(0, ## fmt, NULL) __android_rest(fmt))
534
535#define android_writeLog(prio, tag, text) \
536 __android_log_write(prio, tag, text)
537
538#define android_bWriteLog(tag, payload, len) \
539 __android_log_bwrite(tag, payload, len)
540#define android_btWriteLog(tag, type, payload, len) \
541 __android_log_btwrite(tag, type, payload, len)
542
543// TODO: remove these prototypes and their users
544#define android_testLog(prio, tag) (1)
545#define android_writevLog(vec,num) do{}while(0)
546#define android_write1Log(str,len) do{}while (0)
547#define android_setMinPriority(tag, prio) do{}while(0)
548//#define android_logToCallback(func) do{}while(0)
549#define android_logToFile(tag, file) (0)
550#define android_logToFd(tag, fd) (0)
551
Mark Salyzyn42958412013-11-22 10:50:27 -0800552typedef enum log_id {
553 LOG_ID_MIN = 0,
554
Colin Cross9227bd32013-07-23 16:59:20 -0700555 LOG_ID_MAIN = 0,
556 LOG_ID_RADIO = 1,
557 LOG_ID_EVENTS = 2,
558 LOG_ID_SYSTEM = 3,
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700559 LOG_ID_CRASH = 4,
Colin Cross9227bd32013-07-23 16:59:20 -0700560
561 LOG_ID_MAX
562} log_id_t;
Mark Salyzyn42958412013-11-22 10:50:27 -0800563#define sizeof_log_id_t sizeof(typeof_log_id_t)
564#define typeof_log_id_t unsigned char
Colin Cross9227bd32013-07-23 16:59:20 -0700565
566/*
Mark Salyzyn95687052014-10-02 11:12:28 -0700567 * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
568 * result of non-zero to expose a log.
569 */
570int __android_log_is_loggable(int prio, const char *tag, int def);
571
572/*
Colin Cross9227bd32013-07-23 16:59:20 -0700573 * Send a simple string to the log.
574 */
575int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
Colin Cross810d19f2014-02-06 20:07:50 -0800576int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
577#if defined(__GNUC__)
578 __attribute__((__format__(printf, 4, 5)))
579#endif
580 ;
Colin Cross9227bd32013-07-23 16:59:20 -0700581
Mark Salyzynf387fa52014-01-03 16:54:28 -0800582#ifdef __cplusplus
583}
584#endif
Colin Cross9227bd32013-07-23 16:59:20 -0700585
Mark Salyzyn819c58a2013-11-22 12:39:43 -0800586#endif /* _LIBS_LOG_LOG_H */