blob: 9b26839a4ac91205f11f153da065ac8f10d556af [file] [log] [blame]
David 'Digit' Turnerebefc482009-05-29 14:45:04 +02001/*
2 * Copyright (C) 2009 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#ifndef _ANDROID_LOG_H
18#define _ANDROID_LOG_H
19
20/******************************************************************
21 *
22 * IMPORTANT NOTICE:
23 *
24 * This file is part of Android's set of stable system headers
25 * exposed by the Android NDK (Native Development Kit) since
26 * platform release 1.5
27 *
28 * Third-party source AND binary code relies on the definitions
29 * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
30 *
31 * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
32 * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
33 * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
34 * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
35 */
36
37/*
38 * Support routines to send messages to the Android in-kernel log buffer,
39 * which can later be accessed through the 'logcat' utility.
40 *
41 * Each log message must have
42 * - a priority
43 * - a log tag
44 * - some text
45 *
46 * The tag normally corresponds to the component that emits the log message,
47 * and should be reasonably small.
48 *
49 * Log message text may be truncated to less than an implementation-specific
50 * limit (e.g. 1023 characters max).
51 *
52 * Note that a newline character ("\n") will be appended automatically to your
53 * log message, if not already there. It is not possible to send several messages
54 * and have them appear on a single line in logcat.
55 *
56 * PLEASE USE LOGS WITH MODERATION:
57 *
58 * - Sending log messages eats CPU and slow down your application and the
59 * system.
60 *
61 * - The circular log buffer is pretty small (<64KB), sending many messages
62 * might push off other important log messages from the rest of the system.
63 *
64 * - In release builds, only send log messages to account for exceptional
65 * conditions.
66 *
67 * NOTE: These functions MUST be implemented by /system/lib/liblog.so
68 */
69
Mark Salyzyn6584d0a2016-09-28 13:26:55 -070070#if !defined(_WIN32)
71#include <pthread.h>
72#endif
David 'Digit' Turnerebefc482009-05-29 14:45:04 +020073#include <stdarg.h>
Mark Salyzyn6584d0a2016-09-28 13:26:55 -070074#include <stdint.h>
75#include <stdio.h>
76#include <sys/types.h>
77#include <time.h>
78#include <unistd.h>
79
80#include <log/uio.h>
David 'Digit' Turnerebefc482009-05-29 14:45:04 +020081
82#ifdef __cplusplus
83extern "C" {
84#endif
85
86/*
87 * Android log priority values, in ascending priority order.
88 */
89typedef enum android_LogPriority {
90 ANDROID_LOG_UNKNOWN = 0,
91 ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
92 ANDROID_LOG_VERBOSE,
93 ANDROID_LOG_DEBUG,
94 ANDROID_LOG_INFO,
95 ANDROID_LOG_WARN,
96 ANDROID_LOG_ERROR,
97 ANDROID_LOG_FATAL,
98 ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
99} android_LogPriority;
100
101/*
Mark Salyzyndf7a4c62016-08-23 10:23:36 -0700102 * Release any logger resources (a new log write will immediately re-acquire)
103 */
104void __android_log_close();
105
106/*
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200107 * Send a simple string to the log.
108 */
109int __android_log_write(int prio, const char *tag, const char *text);
110
111/*
112 * Send a formatted string to the log, used like printf(fmt,...)
113 */
114int __android_log_print(int prio, const char *tag, const char *fmt, ...)
115#if defined(__GNUC__)
Dan Willemsen0cddcc62014-06-11 15:36:58 -0700116#ifdef __USE_MINGW_ANSI_STDIO
Andrew Hsiehad832852014-05-09 11:50:45 +0800117#if __USE_MINGW_ANSI_STDIO
118 __attribute__ ((format(gnu_printf, 3, 4)))
119#else
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200120 __attribute__ ((format(printf, 3, 4)))
121#endif
Dan Willemsen0cddcc62014-06-11 15:36:58 -0700122#else
123 __attribute__ ((format(printf, 3, 4)))
124#endif
Andrew Hsiehad832852014-05-09 11:50:45 +0800125#endif
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200126 ;
127
128/*
129 * A variant of __android_log_print() that takes a va_list to list
130 * additional parameters.
131 */
132int __android_log_vprint(int prio, const char *tag,
133 const char *fmt, va_list ap);
134
135/*
Elliott Hughesda6b2e22014-04-23 14:57:32 -0700136 * Log an assertion failure and abort the process to have a chance
137 * to inspect it if a debugger is attached. This uses the FATAL priority.
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200138 */
139void __android_log_assert(const char *cond, const char *tag,
Elliott Hughesda6b2e22014-04-23 14:57:32 -0700140 const char *fmt, ...)
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200141#if defined(__GNUC__)
Elliott Hughes665051c2016-06-20 17:21:59 -0700142 __attribute__ ((__noreturn__))
Dan Willemsen0cddcc62014-06-11 15:36:58 -0700143#ifdef __USE_MINGW_ANSI_STDIO
Andrew Hsiehad832852014-05-09 11:50:45 +0800144#if __USE_MINGW_ANSI_STDIO
145 __attribute__ ((format(gnu_printf, 3, 4)))
146#else
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200147 __attribute__ ((format(printf, 3, 4)))
148#endif
Dan Willemsen0cddcc62014-06-11 15:36:58 -0700149#else
150 __attribute__ ((format(printf, 3, 4)))
151#endif
Andrew Hsiehad832852014-05-09 11:50:45 +0800152#endif
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200153 ;
154
Mark Salyzyn6584d0a2016-09-28 13:26:55 -0700155//
156// C/C++ logging functions. See the logging documentation for API details.
157//
158// We'd like these to be available from C code (in case we import some from
159// somewhere), so this has a C interface.
160//
161// The output will be correct when the log file is shared between multiple
162// threads and/or multiple processes so long as the operating system
163// supports O_APPEND. These calls have mutex-protected data structures
164// and so are NOT reentrant. Do not use LOG in a signal handler.
165//
166
167// This file uses ", ## __VA_ARGS__" zero-argument token pasting to
168// work around issues with debug-only syntax errors in assertions
169// that are missing format strings. See commit
170// 19299904343daf191267564fe32e6cd5c165cd42
171#if defined(__clang__)
172#pragma clang diagnostic push
173#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
174#endif
175
176int __android_log_bwrite(int32_t tag, const void *payload, size_t len);
177int __android_log_btwrite(int32_t tag, char type, const void *payload,
178 size_t len);
179int __android_log_bswrite(int32_t tag, const char *payload);
180
Mark Salyzyn6584d0a2016-09-28 13:26:55 -0700181// ---------------------------------------------------------------------
182
183/*
184 * Normally we strip ALOGV (VERBOSE messages) from release builds.
185 * You can modify this (for example with "#define LOG_NDEBUG 0"
186 * at the top of your source file) to change that behavior.
187 */
188#ifndef LOG_NDEBUG
189#ifdef NDEBUG
190#define LOG_NDEBUG 1
191#else
192#define LOG_NDEBUG 0
193#endif
194#endif
195
196/*
197 * This is the local tag used for the following simplified
198 * logging macros. You can change this preprocessor definition
199 * before using the other macros to change the tag.
200 */
201#ifndef LOG_TAG
202#define LOG_TAG NULL
203#endif
204
205// ---------------------------------------------------------------------
206
207#ifndef __predict_false
208#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
209#endif
210
211/*
212 * -DLINT_RLOG in sources that you want to enforce that all logging
213 * goes to the radio log buffer. If any logging goes to any of the other
214 * log buffers, there will be a compile or link error to highlight the
215 * problem. This is not a replacement for a full audit of the code since
216 * this only catches compiled code, not ifdef'd debug code. Options to
217 * defining this, either temporarily to do a spot check, or permanently
218 * to enforce, in all the communications trees; We have hopes to ensure
219 * that by supplying just the radio log buffer that the communications
220 * teams will have their one-stop shop for triaging issues.
221 */
222#ifndef LINT_RLOG
223
224/*
225 * Simplified macro to send a verbose log message using the current LOG_TAG.
226 */
227#ifndef ALOGV
228#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
229#if LOG_NDEBUG
230#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
231#else
232#define ALOGV(...) __ALOGV(__VA_ARGS__)
233#endif
234#endif
235
236#ifndef ALOGV_IF
237#if LOG_NDEBUG
238#define ALOGV_IF(cond, ...) ((void)0)
239#else
240#define ALOGV_IF(cond, ...) \
241 ( (__predict_false(cond)) \
242 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
243 : (void)0 )
244#endif
245#endif
246
247/*
248 * Simplified macro to send a debug log message using the current LOG_TAG.
249 */
250#ifndef ALOGD
251#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
252#endif
253
254#ifndef ALOGD_IF
255#define ALOGD_IF(cond, ...) \
256 ( (__predict_false(cond)) \
257 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
258 : (void)0 )
259#endif
260
261/*
262 * Simplified macro to send an info log message using the current LOG_TAG.
263 */
264#ifndef ALOGI
265#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
266#endif
267
268#ifndef ALOGI_IF
269#define ALOGI_IF(cond, ...) \
270 ( (__predict_false(cond)) \
271 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
272 : (void)0 )
273#endif
274
275/*
276 * Simplified macro to send a warning log message using the current LOG_TAG.
277 */
278#ifndef ALOGW
279#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
280#endif
281
282#ifndef ALOGW_IF
283#define ALOGW_IF(cond, ...) \
284 ( (__predict_false(cond)) \
285 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
286 : (void)0 )
287#endif
288
289/*
290 * Simplified macro to send an error log message using the current LOG_TAG.
291 */
292#ifndef ALOGE
293#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
294#endif
295
296#ifndef ALOGE_IF
297#define ALOGE_IF(cond, ...) \
298 ( (__predict_false(cond)) \
299 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
300 : (void)0 )
301#endif
302
303// ---------------------------------------------------------------------
304
305/*
306 * Conditional based on whether the current LOG_TAG is enabled at
307 * verbose priority.
308 */
309#ifndef IF_ALOGV
310#if LOG_NDEBUG
311#define IF_ALOGV() if (false)
312#else
313#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
314#endif
315#endif
316
317/*
318 * Conditional based on whether the current LOG_TAG is enabled at
319 * debug priority.
320 */
321#ifndef IF_ALOGD
322#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
323#endif
324
325/*
326 * Conditional based on whether the current LOG_TAG is enabled at
327 * info priority.
328 */
329#ifndef IF_ALOGI
330#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
331#endif
332
333/*
334 * Conditional based on whether the current LOG_TAG is enabled at
335 * warn priority.
336 */
337#ifndef IF_ALOGW
338#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
339#endif
340
341/*
342 * Conditional based on whether the current LOG_TAG is enabled at
343 * error priority.
344 */
345#ifndef IF_ALOGE
346#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
347#endif
348
349
350// ---------------------------------------------------------------------
351
352/*
353 * Simplified macro to send a verbose system log message using the current LOG_TAG.
354 */
355#ifndef SLOGV
356#define __SLOGV(...) \
357 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
358#if LOG_NDEBUG
359#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
360#else
361#define SLOGV(...) __SLOGV(__VA_ARGS__)
362#endif
363#endif
364
365#ifndef SLOGV_IF
366#if LOG_NDEBUG
367#define SLOGV_IF(cond, ...) ((void)0)
368#else
369#define SLOGV_IF(cond, ...) \
370 ( (__predict_false(cond)) \
371 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
372 : (void)0 )
373#endif
374#endif
375
376/*
377 * Simplified macro to send a debug system log message using the current LOG_TAG.
378 */
379#ifndef SLOGD
380#define SLOGD(...) \
381 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
382#endif
383
384#ifndef SLOGD_IF
385#define SLOGD_IF(cond, ...) \
386 ( (__predict_false(cond)) \
387 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
388 : (void)0 )
389#endif
390
391/*
392 * Simplified macro to send an info system log message using the current LOG_TAG.
393 */
394#ifndef SLOGI
395#define SLOGI(...) \
396 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
397#endif
398
399#ifndef SLOGI_IF
400#define SLOGI_IF(cond, ...) \
401 ( (__predict_false(cond)) \
402 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
403 : (void)0 )
404#endif
405
406/*
407 * Simplified macro to send a warning system log message using the current LOG_TAG.
408 */
409#ifndef SLOGW
410#define SLOGW(...) \
411 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
412#endif
413
414#ifndef SLOGW_IF
415#define SLOGW_IF(cond, ...) \
416 ( (__predict_false(cond)) \
417 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
418 : (void)0 )
419#endif
420
421/*
422 * Simplified macro to send an error system log message using the current LOG_TAG.
423 */
424#ifndef SLOGE
425#define SLOGE(...) \
426 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
427#endif
428
429#ifndef SLOGE_IF
430#define SLOGE_IF(cond, ...) \
431 ( (__predict_false(cond)) \
432 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
433 : (void)0 )
434#endif
435
436#endif /* !LINT_RLOG */
437
438// ---------------------------------------------------------------------
439
440/*
441 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
442 */
443#ifndef RLOGV
444#define __RLOGV(...) \
445 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
446#if LOG_NDEBUG
447#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
448#else
449#define RLOGV(...) __RLOGV(__VA_ARGS__)
450#endif
451#endif
452
453#ifndef RLOGV_IF
454#if LOG_NDEBUG
455#define RLOGV_IF(cond, ...) ((void)0)
456#else
457#define RLOGV_IF(cond, ...) \
458 ( (__predict_false(cond)) \
459 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
460 : (void)0 )
461#endif
462#endif
463
464/*
465 * Simplified macro to send a debug radio log message using the current LOG_TAG.
466 */
467#ifndef RLOGD
468#define RLOGD(...) \
469 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
470#endif
471
472#ifndef RLOGD_IF
473#define RLOGD_IF(cond, ...) \
474 ( (__predict_false(cond)) \
475 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
476 : (void)0 )
477#endif
478
479/*
480 * Simplified macro to send an info radio log message using the current LOG_TAG.
481 */
482#ifndef RLOGI
483#define RLOGI(...) \
484 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
485#endif
486
487#ifndef RLOGI_IF
488#define RLOGI_IF(cond, ...) \
489 ( (__predict_false(cond)) \
490 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
491 : (void)0 )
492#endif
493
494/*
495 * Simplified macro to send a warning radio log message using the current LOG_TAG.
496 */
497#ifndef RLOGW
498#define RLOGW(...) \
499 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
500#endif
501
502#ifndef RLOGW_IF
503#define RLOGW_IF(cond, ...) \
504 ( (__predict_false(cond)) \
505 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
506 : (void)0 )
507#endif
508
509/*
510 * Simplified macro to send an error radio log message using the current LOG_TAG.
511 */
512#ifndef RLOGE
513#define RLOGE(...) \
514 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
515#endif
516
517#ifndef RLOGE_IF
518#define RLOGE_IF(cond, ...) \
519 ( (__predict_false(cond)) \
520 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
521 : (void)0 )
522#endif
523
524
525// ---------------------------------------------------------------------
526
527/*
528 * Log a fatal error. If the given condition fails, this stops program
529 * execution like a normal assertion, but also generating the given message.
530 * It is NOT stripped from release builds. Note that the condition test
531 * is -inverted- from the normal assert() semantics.
532 */
533#ifndef LOG_ALWAYS_FATAL_IF
534#define LOG_ALWAYS_FATAL_IF(cond, ...) \
535 ( (__predict_false(cond)) \
536 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
537 : (void)0 )
538#endif
539
540#ifndef LOG_ALWAYS_FATAL
541#define LOG_ALWAYS_FATAL(...) \
542 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
543#endif
544
545/*
546 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
547 * are stripped out of release builds.
548 */
549#if LOG_NDEBUG
550
551#ifndef LOG_FATAL_IF
552#define LOG_FATAL_IF(cond, ...) ((void)0)
553#endif
554#ifndef LOG_FATAL
555#define LOG_FATAL(...) ((void)0)
556#endif
557
558#else
559
560#ifndef LOG_FATAL_IF
561#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
562#endif
563#ifndef LOG_FATAL
564#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
565#endif
566
567#endif
568
569/*
570 * Assertion that generates a log message when the assertion fails.
571 * Stripped out of release builds. Uses the current LOG_TAG.
572 */
573#ifndef ALOG_ASSERT
574#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
575//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
576#endif
577
578// ---------------------------------------------------------------------
579
580/*
581 * Basic log message macro.
582 *
583 * Example:
584 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
585 *
586 * The second argument may be NULL or "" to indicate the "global" tag.
587 */
588#ifndef ALOG
589#define ALOG(priority, tag, ...) \
590 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
591#endif
592
593/*
594 * Log macro that allows you to specify a number for the priority.
595 */
596#ifndef LOG_PRI
597#define LOG_PRI(priority, tag, ...) \
598 android_printLog(priority, tag, __VA_ARGS__)
599#endif
600
601/*
602 * Log macro that allows you to pass in a varargs ("args" is a va_list).
603 */
604#ifndef LOG_PRI_VA
605#define LOG_PRI_VA(priority, tag, fmt, args) \
606 android_vprintLog(priority, NULL, tag, fmt, args)
607#endif
608
609/*
610 * Conditional given a desired logging priority and tag.
611 */
612#ifndef IF_ALOG
613#define IF_ALOG(priority, tag) \
614 if (android_testLog(ANDROID_##priority, tag))
615#endif
616
617// ---------------------------------------------------------------------
618
619/*
620 * Event logging.
621 */
622
623/*
624 * Event log entry types.
625 */
626typedef enum {
627 /* Special markers for android_log_list_element type */
628 EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
629 EVENT_TYPE_UNKNOWN = '?', /* protocol error */
630
631 /* must match with declaration in java/android/android/util/EventLog.java */
632 EVENT_TYPE_INT = 0, /* uint32_t */
633 EVENT_TYPE_LONG = 1, /* uint64_t */
634 EVENT_TYPE_STRING = 2,
635 EVENT_TYPE_LIST = 3,
636 EVENT_TYPE_FLOAT = 4,
637} AndroidEventLogType;
638#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
639#define typeof_AndroidEventLogType unsigned char
640
641#ifndef LOG_EVENT_INT
642#define LOG_EVENT_INT(_tag, _value) { \
643 int intBuf = _value; \
644 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
645 sizeof(intBuf)); \
646 }
647#endif
648#ifndef LOG_EVENT_LONG
649#define LOG_EVENT_LONG(_tag, _value) { \
650 long long longBuf = _value; \
651 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
652 sizeof(longBuf)); \
653 }
654#endif
655#ifndef LOG_EVENT_FLOAT
656#define LOG_EVENT_FLOAT(_tag, _value) { \
657 float floatBuf = _value; \
658 (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
659 sizeof(floatBuf)); \
660 }
661#endif
662#ifndef LOG_EVENT_STRING
663#define LOG_EVENT_STRING(_tag, _value) \
664 (void) __android_log_bswrite(_tag, _value);
665#endif
666
667typedef enum log_id {
668 LOG_ID_MIN = 0,
669
670#ifndef LINT_RLOG
671 LOG_ID_MAIN = 0,
672#endif
673 LOG_ID_RADIO = 1,
674#ifndef LINT_RLOG
675 LOG_ID_EVENTS = 2,
676 LOG_ID_SYSTEM = 3,
677 LOG_ID_CRASH = 4,
678 LOG_ID_SECURITY = 5,
679 LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
680#endif
681
682 LOG_ID_MAX
683} log_id_t;
684#define sizeof_log_id_t sizeof(typeof_log_id_t)
685#define typeof_log_id_t unsigned char
686
687/* For manipulating lists of events. */
688
689#define ANDROID_MAX_LIST_NEST_DEPTH 8
690
691/*
692 * The opaque context used to manipulate lists of events.
693 */
694typedef struct android_log_context_internal *android_log_context;
695
696/*
697 * Elements returned when reading a list of events.
698 */
699typedef struct {
700 AndroidEventLogType type;
701 uint16_t complete;
702 uint16_t len;
703 union {
704 int32_t int32;
705 int64_t int64;
706 char *string;
707 float float32;
708 } data;
709} android_log_list_element;
710
711/*
712 * Creates a context associated with an event tag to write elements to
713 * the list of events.
714 */
715android_log_context create_android_logger(uint32_t tag);
716
717/* All lists must be braced by a begin and end call */
718/*
719 * NB: If the first level braces are missing when specifying multiple
720 * elements, we will manufacturer a list to embrace it for your API
721 * convenience. For a single element, it will remain solitary.
722 */
723int android_log_write_list_begin(android_log_context ctx);
724int android_log_write_list_end(android_log_context ctx);
725
726int android_log_write_int32(android_log_context ctx, int32_t value);
727int android_log_write_int64(android_log_context ctx, int64_t value);
728int android_log_write_string8(android_log_context ctx, const char *value);
729int android_log_write_string8_len(android_log_context ctx,
730 const char *value, size_t maxlen);
731int android_log_write_float32(android_log_context ctx, float value);
732
733/* Submit the composed list context to the specified logger id */
734/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
735int android_log_write_list(android_log_context ctx, log_id_t id);
736
737/*
738 * Creates a context from a raw buffer representing a list of events to be read.
739 */
740android_log_context create_android_log_parser(const char *msg, size_t len);
741
742android_log_list_element android_log_read_next(android_log_context ctx);
743android_log_list_element android_log_peek_next(android_log_context ctx);
744
745/* Finished with reader or writer context */
746int android_log_destroy(android_log_context *ctx);
747
748/*
749 * ===========================================================================
750 *
751 * The stuff in the rest of this file should not be used directly.
752 */
753
754#define android_printLog(prio, tag, ...) \
755 __android_log_print(prio, tag, __VA_ARGS__)
756
757#define android_vprintLog(prio, cond, tag, ...) \
758 __android_log_vprint(prio, tag, __VA_ARGS__)
759
760/* XXX Macros to work around syntax errors in places where format string
761 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
762 * (happens only in debug builds).
763 */
764
765/* Returns 2nd arg. Used to substitute default value if caller's vararg list
766 * is empty.
767 */
768#define __android_second(dummy, second, ...) second
769
770/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
771 * returns nothing.
772 */
773#define __android_rest(first, ...) , ## __VA_ARGS__
774
775#define android_printAssert(cond, tag, ...) \
776 __android_log_assert(cond, tag, \
777 __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__))
778
779#define android_writeLog(prio, tag, text) \
780 __android_log_write(prio, tag, text)
781
782#define android_bWriteLog(tag, payload, len) \
783 __android_log_bwrite(tag, payload, len)
784#define android_btWriteLog(tag, type, payload, len) \
785 __android_log_btwrite(tag, type, payload, len)
786
787#define android_errorWriteLog(tag, subTag) \
788 __android_log_error_write(tag, subTag, -1, NULL, 0)
789
790#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
791 __android_log_error_write(tag, subTag, uid, data, dataLen)
792
793/*
794 * IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
795 * android_testLog will remain constant in its purpose as a wrapper
796 * for Android logging filter policy, and can be subject to
797 * change. It can be reused by the developers that override
798 * IF_ALOG as a convenient means to reimplement their policy
799 * over Android.
800 */
801#if LOG_NDEBUG /* Production */
802#define android_testLog(prio, tag) \
Mark Salyzyn807e40e2016-09-22 09:56:51 -0700803 (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \
804 ANDROID_LOG_DEBUG) != 0)
Mark Salyzyn6584d0a2016-09-28 13:26:55 -0700805#else
806#define android_testLog(prio, tag) \
Mark Salyzyn807e40e2016-09-22 09:56:51 -0700807 (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \
808 ANDROID_LOG_VERBOSE) != 0)
Mark Salyzyn6584d0a2016-09-28 13:26:55 -0700809#endif
810
811/*
812 * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
813 * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
814 * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
815 * any other value.
816 */
817int __android_log_is_loggable(int prio, const char *tag, int default_prio);
Mark Salyzyn807e40e2016-09-22 09:56:51 -0700818int __android_log_is_loggable_len(int prio, const char *tag, size_t len, int default_prio);
Mark Salyzyn6584d0a2016-09-28 13:26:55 -0700819
Mark Salyzyn6584d0a2016-09-28 13:26:55 -0700820int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
821 uint32_t dataLen);
822
823/*
824 * Send a simple string to the log.
825 */
826int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
827int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
828#if defined(__GNUC__)
829 __attribute__((__format__(printf, 4, 5)))
830#endif
831 ;
832
833#if defined(__clang__)
834#pragma clang diagnostic pop
835#endif
836
David 'Digit' Turnerebefc482009-05-29 14:45:04 +0200837#ifdef __cplusplus
838}
839#endif
840
841#endif /* _ANDROID_LOG_H */