blob: ce253e27245c881b2708c1bf4c1f9d11d15f013a [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
Mark Salyzyn4ff25452015-04-09 16:12:58 -070070#ifndef __predict_false
71#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
72#endif
73
74/*
75 * -DLINT_RLOG in sources that you want to enforce that all logging
76 * goes to the radio log buffer. If any logging goes to any of the other
77 * log buffers, there will be a compile or link error to highlight the
78 * problem. This is not a replacement for a full audit of the code since
79 * this only catches compiled code, not ifdef'd debug code. Options to
80 * defining this, either temporarily to do a spot check, or permanently
81 * to enforce, in all the communications trees; We have hopes to ensure
82 * that by supplying just the radio log buffer that the communications
83 * teams will have their one-stop shop for triaging issues.
84 */
85#ifndef LINT_RLOG
86
Colin Cross9227bd32013-07-23 16:59:20 -070087/*
88 * Simplified macro to send a verbose log message using the current LOG_TAG.
89 */
90#ifndef ALOGV
Colin Cross810d19f2014-02-06 20:07:50 -080091#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -070092#if LOG_NDEBUG
Colin Cross810d19f2014-02-06 20:07:50 -080093#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
Colin Cross9227bd32013-07-23 16:59:20 -070094#else
Colin Cross810d19f2014-02-06 20:07:50 -080095#define ALOGV(...) __ALOGV(__VA_ARGS__)
Colin Cross9227bd32013-07-23 16:59:20 -070096#endif
97#endif
98
Colin Cross9227bd32013-07-23 16:59:20 -070099#ifndef ALOGV_IF
100#if LOG_NDEBUG
101#define ALOGV_IF(cond, ...) ((void)0)
102#else
103#define ALOGV_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700104 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700105 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
106 : (void)0 )
107#endif
108#endif
109
110/*
111 * Simplified macro to send a debug log message using the current LOG_TAG.
112 */
113#ifndef ALOGD
114#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
115#endif
116
117#ifndef ALOGD_IF
118#define ALOGD_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700119 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700120 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
121 : (void)0 )
122#endif
123
124/*
125 * Simplified macro to send an info log message using the current LOG_TAG.
126 */
127#ifndef ALOGI
128#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
129#endif
130
131#ifndef ALOGI_IF
132#define ALOGI_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700133 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700134 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
135 : (void)0 )
136#endif
137
138/*
139 * Simplified macro to send a warning log message using the current LOG_TAG.
140 */
141#ifndef ALOGW
142#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
143#endif
144
145#ifndef ALOGW_IF
146#define ALOGW_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700147 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700148 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
149 : (void)0 )
150#endif
151
152/*
153 * Simplified macro to send an error log message using the current LOG_TAG.
154 */
155#ifndef ALOGE
156#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
157#endif
158
159#ifndef ALOGE_IF
160#define ALOGE_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700161 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700162 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
163 : (void)0 )
164#endif
165
166// ---------------------------------------------------------------------
167
168/*
169 * Conditional based on whether the current LOG_TAG is enabled at
170 * verbose priority.
171 */
172#ifndef IF_ALOGV
173#if LOG_NDEBUG
174#define IF_ALOGV() if (false)
175#else
176#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
177#endif
178#endif
179
180/*
181 * Conditional based on whether the current LOG_TAG is enabled at
182 * debug priority.
183 */
184#ifndef IF_ALOGD
185#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
186#endif
187
188/*
189 * Conditional based on whether the current LOG_TAG is enabled at
190 * info priority.
191 */
192#ifndef IF_ALOGI
193#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
194#endif
195
196/*
197 * Conditional based on whether the current LOG_TAG is enabled at
198 * warn priority.
199 */
200#ifndef IF_ALOGW
201#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
202#endif
203
204/*
205 * Conditional based on whether the current LOG_TAG is enabled at
206 * error priority.
207 */
208#ifndef IF_ALOGE
209#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
210#endif
211
212
213// ---------------------------------------------------------------------
214
215/*
216 * Simplified macro to send a verbose system log message using the current LOG_TAG.
217 */
218#ifndef SLOGV
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700219#define __SLOGV(...) \
220 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700221#if LOG_NDEBUG
Colin Cross810d19f2014-02-06 20:07:50 -0800222#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
Colin Cross9227bd32013-07-23 16:59:20 -0700223#else
Colin Cross810d19f2014-02-06 20:07:50 -0800224#define SLOGV(...) __SLOGV(__VA_ARGS__)
Colin Cross9227bd32013-07-23 16:59:20 -0700225#endif
226#endif
227
Colin Cross9227bd32013-07-23 16:59:20 -0700228#ifndef SLOGV_IF
229#if LOG_NDEBUG
230#define SLOGV_IF(cond, ...) ((void)0)
231#else
232#define SLOGV_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700233 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700234 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
235 : (void)0 )
236#endif
237#endif
238
239/*
240 * Simplified macro to send a debug system log message using the current LOG_TAG.
241 */
242#ifndef SLOGD
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700243#define SLOGD(...) \
244 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700245#endif
246
247#ifndef SLOGD_IF
248#define SLOGD_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700249 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700250 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
251 : (void)0 )
252#endif
253
254/*
255 * Simplified macro to send an info system log message using the current LOG_TAG.
256 */
257#ifndef SLOGI
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700258#define SLOGI(...) \
259 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700260#endif
261
262#ifndef SLOGI_IF
263#define SLOGI_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700264 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700265 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
266 : (void)0 )
267#endif
268
269/*
270 * Simplified macro to send a warning system log message using the current LOG_TAG.
271 */
272#ifndef SLOGW
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700273#define SLOGW(...) \
274 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700275#endif
276
277#ifndef SLOGW_IF
278#define SLOGW_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700279 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700280 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
281 : (void)0 )
282#endif
283
284/*
285 * Simplified macro to send an error system log message using the current LOG_TAG.
286 */
287#ifndef SLOGE
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700288#define SLOGE(...) \
289 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700290#endif
291
292#ifndef SLOGE_IF
293#define SLOGE_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700294 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700295 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
296 : (void)0 )
297#endif
298
Mark Salyzyn4ff25452015-04-09 16:12:58 -0700299#endif /* !LINT_RLOG */
300
Colin Cross9227bd32013-07-23 16:59:20 -0700301// ---------------------------------------------------------------------
302
303/*
304 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
305 */
306#ifndef RLOGV
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700307#define __RLOGV(...) \
308 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700309#if LOG_NDEBUG
Colin Cross810d19f2014-02-06 20:07:50 -0800310#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
Colin Cross9227bd32013-07-23 16:59:20 -0700311#else
Colin Cross810d19f2014-02-06 20:07:50 -0800312#define RLOGV(...) __RLOGV(__VA_ARGS__)
Colin Cross9227bd32013-07-23 16:59:20 -0700313#endif
314#endif
315
Colin Cross9227bd32013-07-23 16:59:20 -0700316#ifndef RLOGV_IF
317#if LOG_NDEBUG
318#define RLOGV_IF(cond, ...) ((void)0)
319#else
320#define RLOGV_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700321 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700322 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
323 : (void)0 )
324#endif
325#endif
326
327/*
328 * Simplified macro to send a debug radio log message using the current LOG_TAG.
329 */
330#ifndef RLOGD
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700331#define RLOGD(...) \
332 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700333#endif
334
335#ifndef RLOGD_IF
336#define RLOGD_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_DEBUG, LOG_TAG, __VA_ARGS__)) \
339 : (void)0 )
340#endif
341
342/*
343 * Simplified macro to send an info radio log message using the current LOG_TAG.
344 */
345#ifndef RLOGI
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700346#define RLOGI(...) \
347 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700348#endif
349
350#ifndef RLOGI_IF
351#define RLOGI_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_INFO, LOG_TAG, __VA_ARGS__)) \
354 : (void)0 )
355#endif
356
357/*
358 * Simplified macro to send a warning radio log message using the current LOG_TAG.
359 */
360#ifndef RLOGW
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700361#define RLOGW(...) \
362 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700363#endif
364
365#ifndef RLOGW_IF
366#define RLOGW_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_WARN, LOG_TAG, __VA_ARGS__)) \
369 : (void)0 )
370#endif
371
372/*
373 * Simplified macro to send an error radio log message using the current LOG_TAG.
374 */
375#ifndef RLOGE
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700376#define RLOGE(...) \
377 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
Colin Cross9227bd32013-07-23 16:59:20 -0700378#endif
379
380#ifndef RLOGE_IF
381#define RLOGE_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700382 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700383 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
384 : (void)0 )
385#endif
386
387
388// ---------------------------------------------------------------------
389
390/*
391 * Log a fatal error. If the given condition fails, this stops program
392 * execution like a normal assertion, but also generating the given message.
393 * It is NOT stripped from release builds. Note that the condition test
394 * is -inverted- from the normal assert() semantics.
395 */
396#ifndef LOG_ALWAYS_FATAL_IF
397#define LOG_ALWAYS_FATAL_IF(cond, ...) \
Mark Salyzynf5af82e2014-10-08 07:47:08 -0700398 ( (__predict_false(cond)) \
Colin Cross9227bd32013-07-23 16:59:20 -0700399 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
400 : (void)0 )
401#endif
402
403#ifndef LOG_ALWAYS_FATAL
404#define LOG_ALWAYS_FATAL(...) \
405 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
406#endif
407
408/*
409 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
410 * are stripped out of release builds.
411 */
412#if LOG_NDEBUG
413
414#ifndef LOG_FATAL_IF
415#define LOG_FATAL_IF(cond, ...) ((void)0)
416#endif
417#ifndef LOG_FATAL
418#define LOG_FATAL(...) ((void)0)
419#endif
420
421#else
422
423#ifndef LOG_FATAL_IF
424#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
425#endif
426#ifndef LOG_FATAL
427#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
428#endif
429
430#endif
431
432/*
433 * Assertion that generates a log message when the assertion fails.
434 * Stripped out of release builds. Uses the current LOG_TAG.
435 */
436#ifndef ALOG_ASSERT
437#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
438//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
439#endif
440
441// ---------------------------------------------------------------------
442
443/*
444 * Basic log message macro.
445 *
446 * Example:
447 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
448 *
449 * The second argument may be NULL or "" to indicate the "global" tag.
450 */
451#ifndef ALOG
452#define ALOG(priority, tag, ...) \
453 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
454#endif
455
456/*
457 * Log macro that allows you to specify a number for the priority.
458 */
459#ifndef LOG_PRI
460#define LOG_PRI(priority, tag, ...) \
461 android_printLog(priority, tag, __VA_ARGS__)
462#endif
463
464/*
465 * Log macro that allows you to pass in a varargs ("args" is a va_list).
466 */
467#ifndef LOG_PRI_VA
468#define LOG_PRI_VA(priority, tag, fmt, args) \
469 android_vprintLog(priority, NULL, tag, fmt, args)
470#endif
471
472/*
473 * Conditional given a desired logging priority and tag.
474 */
475#ifndef IF_ALOG
476#define IF_ALOG(priority, tag) \
477 if (android_testLog(ANDROID_##priority, tag))
478#endif
479
480// ---------------------------------------------------------------------
481
482/*
483 * Event logging.
484 */
485
486/*
487 * Event log entry types. These must match up with the declarations in
488 * java/android/android/util/EventLog.java.
489 */
490typedef enum {
491 EVENT_TYPE_INT = 0,
492 EVENT_TYPE_LONG = 1,
493 EVENT_TYPE_STRING = 2,
494 EVENT_TYPE_LIST = 3,
495} AndroidEventLogType;
Mark Salyzyn42958412013-11-22 10:50:27 -0800496#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
497#define typeof_AndroidEventLogType unsigned char
Colin Cross9227bd32013-07-23 16:59:20 -0700498
499#ifndef LOG_EVENT_INT
500#define LOG_EVENT_INT(_tag, _value) { \
501 int intBuf = _value; \
502 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
503 sizeof(intBuf)); \
504 }
505#endif
506#ifndef LOG_EVENT_LONG
507#define LOG_EVENT_LONG(_tag, _value) { \
508 long long longBuf = _value; \
509 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
510 sizeof(longBuf)); \
511 }
512#endif
513#ifndef LOG_EVENT_STRING
514#define LOG_EVENT_STRING(_tag, _value) \
Nick Kralevich2a4d05a2014-07-01 10:57:16 -0700515 (void) __android_log_bswrite(_tag, _value);
Colin Cross9227bd32013-07-23 16:59:20 -0700516#endif
517/* TODO: something for LIST */
518
519/*
520 * ===========================================================================
521 *
522 * The stuff in the rest of this file should not be used directly.
523 */
524
525#define android_printLog(prio, tag, fmt...) \
526 __android_log_print(prio, tag, fmt)
527
528#define android_vprintLog(prio, cond, tag, fmt...) \
529 __android_log_vprint(prio, tag, fmt)
530
531/* XXX Macros to work around syntax errors in places where format string
532 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
533 * (happens only in debug builds).
534 */
535
536/* Returns 2nd arg. Used to substitute default value if caller's vararg list
537 * is empty.
538 */
539#define __android_second(dummy, second, ...) second
540
541/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
542 * returns nothing.
543 */
544#define __android_rest(first, ...) , ## __VA_ARGS__
545
546#define android_printAssert(cond, tag, fmt...) \
547 __android_log_assert(cond, tag, \
548 __android_second(0, ## fmt, NULL) __android_rest(fmt))
549
550#define android_writeLog(prio, tag, text) \
551 __android_log_write(prio, tag, text)
552
553#define android_bWriteLog(tag, payload, len) \
554 __android_log_bwrite(tag, payload, len)
555#define android_btWriteLog(tag, type, payload, len) \
556 __android_log_btwrite(tag, type, payload, len)
557
Mark Salyzyn1df92e52015-02-09 15:15:56 -0800558/*
559 * IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
560 * android_testLog will remain constant in its purpose as a wrapper
561 * for Android logging filter policy, and can be subject to
562 * change. It can be reused by the developers that override
563 * IF_ALOG as a convenient means to reimplement their policy
564 * over Android.
565 */
Andreas Gampef45bbe42015-02-09 16:13:33 -0800566#if LOG_NDEBUG /* Production */
Mark Salyzyn1df92e52015-02-09 15:15:56 -0800567#define android_testLog(prio, tag) \
568 (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
569#else
570#define android_testLog(prio, tag) \
571 (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
572#endif
573
Colin Cross9227bd32013-07-23 16:59:20 -0700574// TODO: remove these prototypes and their users
Colin Cross9227bd32013-07-23 16:59:20 -0700575#define android_writevLog(vec,num) do{}while(0)
576#define android_write1Log(str,len) do{}while (0)
577#define android_setMinPriority(tag, prio) do{}while(0)
578//#define android_logToCallback(func) do{}while(0)
579#define android_logToFile(tag, file) (0)
580#define android_logToFd(tag, fd) (0)
581
Mark Salyzyn42958412013-11-22 10:50:27 -0800582typedef enum log_id {
583 LOG_ID_MIN = 0,
584
Mark Salyzyn4ff25452015-04-09 16:12:58 -0700585#ifndef LINT_RLOG
Colin Cross9227bd32013-07-23 16:59:20 -0700586 LOG_ID_MAIN = 0,
Mark Salyzyn4ff25452015-04-09 16:12:58 -0700587#endif
Colin Cross9227bd32013-07-23 16:59:20 -0700588 LOG_ID_RADIO = 1,
Mark Salyzyn4ff25452015-04-09 16:12:58 -0700589#ifndef LINT_RLOG
Colin Cross9227bd32013-07-23 16:59:20 -0700590 LOG_ID_EVENTS = 2,
591 LOG_ID_SYSTEM = 3,
Mark Salyzyn99f47a92014-04-07 14:58:08 -0700592 LOG_ID_CRASH = 4,
Mark Salyzyn4ff25452015-04-09 16:12:58 -0700593#endif
Colin Cross9227bd32013-07-23 16:59:20 -0700594
595 LOG_ID_MAX
596} log_id_t;
Mark Salyzyn42958412013-11-22 10:50:27 -0800597#define sizeof_log_id_t sizeof(typeof_log_id_t)
598#define typeof_log_id_t unsigned char
Colin Cross9227bd32013-07-23 16:59:20 -0700599
600/*
Mark Salyzyn95687052014-10-02 11:12:28 -0700601 * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
602 * result of non-zero to expose a log.
603 */
604int __android_log_is_loggable(int prio, const char *tag, int def);
605
606/*
Colin Cross9227bd32013-07-23 16:59:20 -0700607 * Send a simple string to the log.
608 */
609int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
Colin Cross810d19f2014-02-06 20:07:50 -0800610int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
611#if defined(__GNUC__)
612 __attribute__((__format__(printf, 4, 5)))
613#endif
614 ;
Colin Cross9227bd32013-07-23 16:59:20 -0700615
Mark Salyzynf387fa52014-01-03 16:54:28 -0800616#ifdef __cplusplus
617}
618#endif
Colin Cross9227bd32013-07-23 16:59:20 -0700619
Mark Salyzyn819c58a2013-11-22 12:39:43 -0800620#endif /* _LIBS_LOG_LOG_H */