blob: e606a842fbba8900fa535987309f8cafe603244e [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/*
Mark Salyzyn9dd65102016-02-17 16:08:13 -0800487 * Event log entry types.
Colin Cross9227bd32013-07-23 16:59:20 -0700488 */
489typedef enum {
Mark Salyzyn9dd65102016-02-17 16:08:13 -0800490 /* Special markers for android_log_list_element type */
491 EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
492 EVENT_TYPE_UNKNOWN = '?', /* protocol error */
493
494 /* must match with declaration in java/android/android/util/EventLog.java */
495 EVENT_TYPE_INT = 0, /* uint32_t */
496 EVENT_TYPE_LONG = 1, /* uint64_t */
497 EVENT_TYPE_STRING = 2,
498 EVENT_TYPE_LIST = 3,
499 EVENT_TYPE_FLOAT = 4,
Colin Cross9227bd32013-07-23 16:59:20 -0700500} AndroidEventLogType;
Mark Salyzyn42958412013-11-22 10:50:27 -0800501#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
502#define typeof_AndroidEventLogType unsigned char
Colin Cross9227bd32013-07-23 16:59:20 -0700503
504#ifndef LOG_EVENT_INT
505#define LOG_EVENT_INT(_tag, _value) { \
506 int intBuf = _value; \
507 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
508 sizeof(intBuf)); \
509 }
510#endif
511#ifndef LOG_EVENT_LONG
512#define LOG_EVENT_LONG(_tag, _value) { \
513 long long longBuf = _value; \
514 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
515 sizeof(longBuf)); \
516 }
517#endif
Jeff Brown44193d92015-04-28 12:47:02 -0700518#ifndef LOG_EVENT_FLOAT
519#define LOG_EVENT_FLOAT(_tag, _value) { \
520 float floatBuf = _value; \
521 (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
522 sizeof(floatBuf)); \
523 }
524#endif
Colin Cross9227bd32013-07-23 16:59:20 -0700525#ifndef LOG_EVENT_STRING
526#define LOG_EVENT_STRING(_tag, _value) \
Nick Kralevich2a4d05a2014-07-01 10:57:16 -0700527 (void) __android_log_bswrite(_tag, _value);
Colin Cross9227bd32013-07-23 16:59:20 -0700528#endif
Mark Salyzyn9dd65102016-02-17 16:08:13 -0800529
530typedef enum log_id {
531 LOG_ID_MIN = 0,
532
533#ifndef LINT_RLOG
534 LOG_ID_MAIN = 0,
535#endif
536 LOG_ID_RADIO = 1,
537#ifndef LINT_RLOG
538 LOG_ID_EVENTS = 2,
539 LOG_ID_SYSTEM = 3,
540 LOG_ID_CRASH = 4,
541 LOG_ID_SECURITY = 5,
542 LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
543#endif
544
545 LOG_ID_MAX
546} log_id_t;
547#define sizeof_log_id_t sizeof(typeof_log_id_t)
548#define typeof_log_id_t unsigned char
549
550/* For manipulating lists of events. */
551
552#define ANDROID_MAX_LIST_NEST_DEPTH 8
553
554/*
555 * The opaque context used to manipulate lists of events.
556 */
557typedef struct android_log_context_internal *android_log_context;
558
559/*
560 * Elements returned when reading a list of events.
561 */
562typedef struct {
563 AndroidEventLogType type;
564 uint16_t complete;
565 uint16_t len;
566 union {
567 int32_t int32;
568 int64_t int64;
569 char *string;
570 float float32;
571 } data;
572} android_log_list_element;
573
574/*
575 * Creates a context associated with an event tag to write elements to
576 * the list of events.
577 */
578android_log_context create_android_logger(uint32_t tag);
579
580/* All lists must be braced by a begin and end call */
581/*
582 * NB: If the first level braces are missing when specifying multiple
583 * elements, we will manufacturer a list to embrace it for your API
584 * convenience. For a single element, it will remain solitary.
585 */
586int android_log_write_list_begin(android_log_context ctx);
587int android_log_write_list_end(android_log_context ctx);
588
589int android_log_write_int32(android_log_context ctx, int32_t value);
590int android_log_write_int64(android_log_context ctx, int64_t value);
591int android_log_write_string8(android_log_context ctx, const char *value);
Mark Salyzyn1d5afc92016-02-25 08:41:25 -0800592int android_log_write_string8_len(android_log_context ctx,
593 const char *value, size_t maxlen);
Mark Salyzyn9dd65102016-02-17 16:08:13 -0800594int android_log_write_float32(android_log_context ctx, float value);
595
596/* Submit the composed list context to the specified logger id */
597/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
598int android_log_write_list(android_log_context ctx, log_id_t id);
599
600/*
601 * Creates a context from a raw buffer representing a list of events to be read.
602 */
603android_log_context create_android_log_parser(const char *msg, size_t len);
604
605android_log_list_element android_log_read_next(android_log_context ctx);
606android_log_list_element android_log_peek_next(android_log_context ctx);
607
608/* Finished with reader or writer context */
609int android_log_destroy(android_log_context *ctx);
Colin Cross9227bd32013-07-23 16:59:20 -0700610
611/*
612 * ===========================================================================
613 *
614 * The stuff in the rest of this file should not be used directly.
615 */
616
617#define android_printLog(prio, tag, fmt...) \
618 __android_log_print(prio, tag, fmt)
619
620#define android_vprintLog(prio, cond, tag, fmt...) \
621 __android_log_vprint(prio, tag, fmt)
622
623/* XXX Macros to work around syntax errors in places where format string
624 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
625 * (happens only in debug builds).
626 */
627
628/* Returns 2nd arg. Used to substitute default value if caller's vararg list
629 * is empty.
630 */
631#define __android_second(dummy, second, ...) second
632
633/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
634 * returns nothing.
635 */
636#define __android_rest(first, ...) , ## __VA_ARGS__
637
638#define android_printAssert(cond, tag, fmt...) \
639 __android_log_assert(cond, tag, \
640 __android_second(0, ## fmt, NULL) __android_rest(fmt))
641
642#define android_writeLog(prio, tag, text) \
643 __android_log_write(prio, tag, text)
644
645#define android_bWriteLog(tag, payload, len) \
646 __android_log_bwrite(tag, payload, len)
647#define android_btWriteLog(tag, type, payload, len) \
648 __android_log_btwrite(tag, type, payload, len)
649
William Luh964428c2015-08-13 10:41:58 -0700650#define android_errorWriteLog(tag, subTag) \
651 __android_log_error_write(tag, subTag, -1, NULL, 0)
652
653#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
654 __android_log_error_write(tag, subTag, uid, data, dataLen)
655
Mark Salyzyn1df92e52015-02-09 15:15:56 -0800656/*
657 * IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
658 * android_testLog will remain constant in its purpose as a wrapper
659 * for Android logging filter policy, and can be subject to
660 * change. It can be reused by the developers that override
661 * IF_ALOG as a convenient means to reimplement their policy
662 * over Android.
663 */
Andreas Gampef45bbe42015-02-09 16:13:33 -0800664#if LOG_NDEBUG /* Production */
Mark Salyzyn1df92e52015-02-09 15:15:56 -0800665#define android_testLog(prio, tag) \
666 (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
667#else
668#define android_testLog(prio, tag) \
669 (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
670#endif
671
Colin Cross9227bd32013-07-23 16:59:20 -0700672/*
Mark Salyzyn95687052014-10-02 11:12:28 -0700673 * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
Mark Salyzyn2d2e0a52015-11-06 12:26:52 -0800674 * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
675 * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
676 * any other value.
Mark Salyzyn95687052014-10-02 11:12:28 -0700677 */
Mark Salyzyn2d2e0a52015-11-06 12:26:52 -0800678int __android_log_is_loggable(int prio, const char *tag, int default_prio);
Mark Salyzyn95687052014-10-02 11:12:28 -0700679
Mark Salyzynffbd86f2015-12-04 10:59:45 -0800680int __android_log_security(); /* Device Owner is present */
681
William Luh964428c2015-08-13 10:41:58 -0700682int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
683 uint32_t dataLen);
684
Mark Salyzyn95687052014-10-02 11:12:28 -0700685/*
Colin Cross9227bd32013-07-23 16:59:20 -0700686 * Send a simple string to the log.
687 */
688int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
Colin Cross810d19f2014-02-06 20:07:50 -0800689int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
690#if defined(__GNUC__)
691 __attribute__((__format__(printf, 4, 5)))
692#endif
693 ;
Colin Cross9227bd32013-07-23 16:59:20 -0700694
Mark Salyzynf387fa52014-01-03 16:54:28 -0800695#ifdef __cplusplus
696}
697#endif
Colin Cross9227bd32013-07-23 16:59:20 -0700698
Mark Salyzyn819c58a2013-11-22 12:39:43 -0800699#endif /* _LIBS_LOG_LOG_H */