summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2016-09-28 15:26:55 -0500
committerMark Salyzyn2016-09-30 14:47:05 -0500
commit6584d0a35ab7722bdc6590525dee29f72f0ec576 (patch)
tree6781f6f444cfab89b4e1b6bc4dc6ac555afefa39
parenta166708d1541007ab5502040051e31863a29edce (diff)
downloadplatform-system-core-6584d0a35ab7722bdc6590525dee29f72f0ec576.tar.gz
platform-system-core-6584d0a35ab7722bdc6590525dee29f72f0ec576.tar.xz
platform-system-core-6584d0a35ab7722bdc6590525dee29f72f0ec576.zip
liblog: Replace log/log.h with android/log.h
Move all liblog related content into android/log.h, and make log/log.h points to android/log.h. Test: Compile Bug: 26552300 Bug: 31289077 Change-Id: I858e0ebe047b86f2a8530a99bc9c380d3d58edbb
-rw-r--r--include/android/log.h694
-rw-r--r--include/log/log.h720
-rw-r--r--include/log/logd.h2
-rw-r--r--include/log/logger.h2
-rw-r--r--include/log/logprint.h2
-rw-r--r--include/private/android_logger.h2
-rw-r--r--liblog/README2
-rw-r--r--liblog/event_tag_map.c2
-rw-r--r--liblog/fake_log_device.c2
-rw-r--r--liblog/fake_writer.c2
-rw-r--r--liblog/log_event_list.c2
-rw-r--r--liblog/log_event_write.c2
-rw-r--r--liblog/logd_reader.c2
-rw-r--r--liblog/logd_writer.c2
-rw-r--r--liblog/logger.h2
-rw-r--r--liblog/logger_name.c2
-rw-r--r--liblog/logger_read.c2
-rw-r--r--liblog/logger_write.c2
-rw-r--r--liblog/logprint.c2
-rw-r--r--liblog/pmsg_writer.c2
-rw-r--r--liblog/tests/liblog_benchmark.cpp2
-rw-r--r--liblog/tests/liblog_test.cpp2
22 files changed, 714 insertions, 740 deletions
diff --git a/include/android/log.h b/include/android/log.h
index a4973b272..de5502a8f 100644
--- a/include/android/log.h
+++ b/include/android/log.h
@@ -67,7 +67,17 @@
67 * NOTE: These functions MUST be implemented by /system/lib/liblog.so 67 * NOTE: These functions MUST be implemented by /system/lib/liblog.so
68 */ 68 */
69 69
70#if !defined(_WIN32)
71#include <pthread.h>
72#endif
70#include <stdarg.h> 73#include <stdarg.h>
74#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>
71 81
72#ifdef __cplusplus 82#ifdef __cplusplus
73extern "C" { 83extern "C" {
@@ -142,6 +152,690 @@ void __android_log_assert(const char *cond, const char *tag,
142#endif 152#endif
143 ; 153 ;
144 154
155//
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
181int __android_log_security_bwrite(int32_t tag, const void *payload, size_t len);
182int __android_log_security_bswrite(int32_t tag, const char *payload);
183
184// ---------------------------------------------------------------------
185
186/*
187 * Normally we strip ALOGV (VERBOSE messages) from release builds.
188 * You can modify this (for example with "#define LOG_NDEBUG 0"
189 * at the top of your source file) to change that behavior.
190 */
191#ifndef LOG_NDEBUG
192#ifdef NDEBUG
193#define LOG_NDEBUG 1
194#else
195#define LOG_NDEBUG 0
196#endif
197#endif
198
199/*
200 * This is the local tag used for the following simplified
201 * logging macros. You can change this preprocessor definition
202 * before using the other macros to change the tag.
203 */
204#ifndef LOG_TAG
205#define LOG_TAG NULL
206#endif
207
208// ---------------------------------------------------------------------
209
210#ifndef __predict_false
211#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
212#endif
213
214/*
215 * -DLINT_RLOG in sources that you want to enforce that all logging
216 * goes to the radio log buffer. If any logging goes to any of the other
217 * log buffers, there will be a compile or link error to highlight the
218 * problem. This is not a replacement for a full audit of the code since
219 * this only catches compiled code, not ifdef'd debug code. Options to
220 * defining this, either temporarily to do a spot check, or permanently
221 * to enforce, in all the communications trees; We have hopes to ensure
222 * that by supplying just the radio log buffer that the communications
223 * teams will have their one-stop shop for triaging issues.
224 */
225#ifndef LINT_RLOG
226
227/*
228 * Simplified macro to send a verbose log message using the current LOG_TAG.
229 */
230#ifndef ALOGV
231#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
232#if LOG_NDEBUG
233#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
234#else
235#define ALOGV(...) __ALOGV(__VA_ARGS__)
236#endif
237#endif
238
239#ifndef ALOGV_IF
240#if LOG_NDEBUG
241#define ALOGV_IF(cond, ...) ((void)0)
242#else
243#define ALOGV_IF(cond, ...) \
244 ( (__predict_false(cond)) \
245 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
246 : (void)0 )
247#endif
248#endif
249
250/*
251 * Simplified macro to send a debug log message using the current LOG_TAG.
252 */
253#ifndef ALOGD
254#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
255#endif
256
257#ifndef ALOGD_IF
258#define ALOGD_IF(cond, ...) \
259 ( (__predict_false(cond)) \
260 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
261 : (void)0 )
262#endif
263
264/*
265 * Simplified macro to send an info log message using the current LOG_TAG.
266 */
267#ifndef ALOGI
268#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
269#endif
270
271#ifndef ALOGI_IF
272#define ALOGI_IF(cond, ...) \
273 ( (__predict_false(cond)) \
274 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
275 : (void)0 )
276#endif
277
278/*
279 * Simplified macro to send a warning log message using the current LOG_TAG.
280 */
281#ifndef ALOGW
282#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
283#endif
284
285#ifndef ALOGW_IF
286#define ALOGW_IF(cond, ...) \
287 ( (__predict_false(cond)) \
288 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
289 : (void)0 )
290#endif
291
292/*
293 * Simplified macro to send an error log message using the current LOG_TAG.
294 */
295#ifndef ALOGE
296#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
297#endif
298
299#ifndef ALOGE_IF
300#define ALOGE_IF(cond, ...) \
301 ( (__predict_false(cond)) \
302 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
303 : (void)0 )
304#endif
305
306// ---------------------------------------------------------------------
307
308/*
309 * Conditional based on whether the current LOG_TAG is enabled at
310 * verbose priority.
311 */
312#ifndef IF_ALOGV
313#if LOG_NDEBUG
314#define IF_ALOGV() if (false)
315#else
316#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
317#endif
318#endif
319
320/*
321 * Conditional based on whether the current LOG_TAG is enabled at
322 * debug priority.
323 */
324#ifndef IF_ALOGD
325#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
326#endif
327
328/*
329 * Conditional based on whether the current LOG_TAG is enabled at
330 * info priority.
331 */
332#ifndef IF_ALOGI
333#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
334#endif
335
336/*
337 * Conditional based on whether the current LOG_TAG is enabled at
338 * warn priority.
339 */
340#ifndef IF_ALOGW
341#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
342#endif
343
344/*
345 * Conditional based on whether the current LOG_TAG is enabled at
346 * error priority.
347 */
348#ifndef IF_ALOGE
349#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
350#endif
351
352
353// ---------------------------------------------------------------------
354
355/*
356 * Simplified macro to send a verbose system log message using the current LOG_TAG.
357 */
358#ifndef SLOGV
359#define __SLOGV(...) \
360 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
361#if LOG_NDEBUG
362#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
363#else
364#define SLOGV(...) __SLOGV(__VA_ARGS__)
365#endif
366#endif
367
368#ifndef SLOGV_IF
369#if LOG_NDEBUG
370#define SLOGV_IF(cond, ...) ((void)0)
371#else
372#define SLOGV_IF(cond, ...) \
373 ( (__predict_false(cond)) \
374 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
375 : (void)0 )
376#endif
377#endif
378
379/*
380 * Simplified macro to send a debug system log message using the current LOG_TAG.
381 */
382#ifndef SLOGD
383#define SLOGD(...) \
384 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
385#endif
386
387#ifndef SLOGD_IF
388#define SLOGD_IF(cond, ...) \
389 ( (__predict_false(cond)) \
390 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
391 : (void)0 )
392#endif
393
394/*
395 * Simplified macro to send an info system log message using the current LOG_TAG.
396 */
397#ifndef SLOGI
398#define SLOGI(...) \
399 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
400#endif
401
402#ifndef SLOGI_IF
403#define SLOGI_IF(cond, ...) \
404 ( (__predict_false(cond)) \
405 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
406 : (void)0 )
407#endif
408
409/*
410 * Simplified macro to send a warning system log message using the current LOG_TAG.
411 */
412#ifndef SLOGW
413#define SLOGW(...) \
414 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
415#endif
416
417#ifndef SLOGW_IF
418#define SLOGW_IF(cond, ...) \
419 ( (__predict_false(cond)) \
420 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
421 : (void)0 )
422#endif
423
424/*
425 * Simplified macro to send an error system log message using the current LOG_TAG.
426 */
427#ifndef SLOGE
428#define SLOGE(...) \
429 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
430#endif
431
432#ifndef SLOGE_IF
433#define SLOGE_IF(cond, ...) \
434 ( (__predict_false(cond)) \
435 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
436 : (void)0 )
437#endif
438
439#endif /* !LINT_RLOG */
440
441// ---------------------------------------------------------------------
442
443/*
444 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
445 */
446#ifndef RLOGV
447#define __RLOGV(...) \
448 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
449#if LOG_NDEBUG
450#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
451#else
452#define RLOGV(...) __RLOGV(__VA_ARGS__)
453#endif
454#endif
455
456#ifndef RLOGV_IF
457#if LOG_NDEBUG
458#define RLOGV_IF(cond, ...) ((void)0)
459#else
460#define RLOGV_IF(cond, ...) \
461 ( (__predict_false(cond)) \
462 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
463 : (void)0 )
464#endif
465#endif
466
467/*
468 * Simplified macro to send a debug radio log message using the current LOG_TAG.
469 */
470#ifndef RLOGD
471#define RLOGD(...) \
472 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
473#endif
474
475#ifndef RLOGD_IF
476#define RLOGD_IF(cond, ...) \
477 ( (__predict_false(cond)) \
478 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
479 : (void)0 )
480#endif
481
482/*
483 * Simplified macro to send an info radio log message using the current LOG_TAG.
484 */
485#ifndef RLOGI
486#define RLOGI(...) \
487 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
488#endif
489
490#ifndef RLOGI_IF
491#define RLOGI_IF(cond, ...) \
492 ( (__predict_false(cond)) \
493 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
494 : (void)0 )
495#endif
496
497/*
498 * Simplified macro to send a warning radio log message using the current LOG_TAG.
499 */
500#ifndef RLOGW
501#define RLOGW(...) \
502 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
503#endif
504
505#ifndef RLOGW_IF
506#define RLOGW_IF(cond, ...) \
507 ( (__predict_false(cond)) \
508 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
509 : (void)0 )
510#endif
511
512/*
513 * Simplified macro to send an error radio log message using the current LOG_TAG.
514 */
515#ifndef RLOGE
516#define RLOGE(...) \
517 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
518#endif
519
520#ifndef RLOGE_IF
521#define RLOGE_IF(cond, ...) \
522 ( (__predict_false(cond)) \
523 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
524 : (void)0 )
525#endif
526
527
528// ---------------------------------------------------------------------
529
530/*
531 * Log a fatal error. If the given condition fails, this stops program
532 * execution like a normal assertion, but also generating the given message.
533 * It is NOT stripped from release builds. Note that the condition test
534 * is -inverted- from the normal assert() semantics.
535 */
536#ifndef LOG_ALWAYS_FATAL_IF
537#define LOG_ALWAYS_FATAL_IF(cond, ...) \
538 ( (__predict_false(cond)) \
539 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
540 : (void)0 )
541#endif
542
543#ifndef LOG_ALWAYS_FATAL
544#define LOG_ALWAYS_FATAL(...) \
545 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
546#endif
547
548/*
549 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
550 * are stripped out of release builds.
551 */
552#if LOG_NDEBUG
553
554#ifndef LOG_FATAL_IF
555#define LOG_FATAL_IF(cond, ...) ((void)0)
556#endif
557#ifndef LOG_FATAL
558#define LOG_FATAL(...) ((void)0)
559#endif
560
561#else
562
563#ifndef LOG_FATAL_IF
564#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
565#endif
566#ifndef LOG_FATAL
567#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
568#endif
569
570#endif
571
572/*
573 * Assertion that generates a log message when the assertion fails.
574 * Stripped out of release builds. Uses the current LOG_TAG.
575 */
576#ifndef ALOG_ASSERT
577#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
578//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
579#endif
580
581// ---------------------------------------------------------------------
582
583/*
584 * Basic log message macro.
585 *
586 * Example:
587 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
588 *
589 * The second argument may be NULL or "" to indicate the "global" tag.
590 */
591#ifndef ALOG
592#define ALOG(priority, tag, ...) \
593 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
594#endif
595
596/*
597 * Log macro that allows you to specify a number for the priority.
598 */
599#ifndef LOG_PRI
600#define LOG_PRI(priority, tag, ...) \
601 android_printLog(priority, tag, __VA_ARGS__)
602#endif
603
604/*
605 * Log macro that allows you to pass in a varargs ("args" is a va_list).
606 */
607#ifndef LOG_PRI_VA
608#define LOG_PRI_VA(priority, tag, fmt, args) \
609 android_vprintLog(priority, NULL, tag, fmt, args)
610#endif
611
612/*
613 * Conditional given a desired logging priority and tag.
614 */
615#ifndef IF_ALOG
616#define IF_ALOG(priority, tag) \
617 if (android_testLog(ANDROID_##priority, tag))
618#endif
619
620// ---------------------------------------------------------------------
621
622/*
623 * Event logging.
624 */
625
626/*
627 * Event log entry types.
628 */
629typedef enum {
630 /* Special markers for android_log_list_element type */
631 EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
632 EVENT_TYPE_UNKNOWN = '?', /* protocol error */
633
634 /* must match with declaration in java/android/android/util/EventLog.java */
635 EVENT_TYPE_INT = 0, /* uint32_t */
636 EVENT_TYPE_LONG = 1, /* uint64_t */
637 EVENT_TYPE_STRING = 2,
638 EVENT_TYPE_LIST = 3,
639 EVENT_TYPE_FLOAT = 4,
640} AndroidEventLogType;
641#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
642#define typeof_AndroidEventLogType unsigned char
643
644#ifndef LOG_EVENT_INT
645#define LOG_EVENT_INT(_tag, _value) { \
646 int intBuf = _value; \
647 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
648 sizeof(intBuf)); \
649 }
650#endif
651#ifndef LOG_EVENT_LONG
652#define LOG_EVENT_LONG(_tag, _value) { \
653 long long longBuf = _value; \
654 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
655 sizeof(longBuf)); \
656 }
657#endif
658#ifndef LOG_EVENT_FLOAT
659#define LOG_EVENT_FLOAT(_tag, _value) { \
660 float floatBuf = _value; \
661 (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
662 sizeof(floatBuf)); \
663 }
664#endif
665#ifndef LOG_EVENT_STRING
666#define LOG_EVENT_STRING(_tag, _value) \
667 (void) __android_log_bswrite(_tag, _value);
668#endif
669
670typedef enum log_id {
671 LOG_ID_MIN = 0,
672
673#ifndef LINT_RLOG
674 LOG_ID_MAIN = 0,
675#endif
676 LOG_ID_RADIO = 1,
677#ifndef LINT_RLOG
678 LOG_ID_EVENTS = 2,
679 LOG_ID_SYSTEM = 3,
680 LOG_ID_CRASH = 4,
681 LOG_ID_SECURITY = 5,
682 LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
683#endif
684
685 LOG_ID_MAX
686} log_id_t;
687#define sizeof_log_id_t sizeof(typeof_log_id_t)
688#define typeof_log_id_t unsigned char
689
690/* For manipulating lists of events. */
691
692#define ANDROID_MAX_LIST_NEST_DEPTH 8
693
694/*
695 * The opaque context used to manipulate lists of events.
696 */
697typedef struct android_log_context_internal *android_log_context;
698
699/*
700 * Elements returned when reading a list of events.
701 */
702typedef struct {
703 AndroidEventLogType type;
704 uint16_t complete;
705 uint16_t len;
706 union {
707 int32_t int32;
708 int64_t int64;
709 char *string;
710 float float32;
711 } data;
712} android_log_list_element;
713
714/*
715 * Creates a context associated with an event tag to write elements to
716 * the list of events.
717 */
718android_log_context create_android_logger(uint32_t tag);
719
720/* All lists must be braced by a begin and end call */
721/*
722 * NB: If the first level braces are missing when specifying multiple
723 * elements, we will manufacturer a list to embrace it for your API
724 * convenience. For a single element, it will remain solitary.
725 */
726int android_log_write_list_begin(android_log_context ctx);
727int android_log_write_list_end(android_log_context ctx);
728
729int android_log_write_int32(android_log_context ctx, int32_t value);
730int android_log_write_int64(android_log_context ctx, int64_t value);
731int android_log_write_string8(android_log_context ctx, const char *value);
732int android_log_write_string8_len(android_log_context ctx,
733 const char *value, size_t maxlen);
734int android_log_write_float32(android_log_context ctx, float value);
735
736/* Submit the composed list context to the specified logger id */
737/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
738int android_log_write_list(android_log_context ctx, log_id_t id);
739
740/*
741 * Creates a context from a raw buffer representing a list of events to be read.
742 */
743android_log_context create_android_log_parser(const char *msg, size_t len);
744
745android_log_list_element android_log_read_next(android_log_context ctx);
746android_log_list_element android_log_peek_next(android_log_context ctx);
747
748/* Finished with reader or writer context */
749int android_log_destroy(android_log_context *ctx);
750
751/*
752 * ===========================================================================
753 *
754 * The stuff in the rest of this file should not be used directly.
755 */
756
757#define android_printLog(prio, tag, ...) \
758 __android_log_print(prio, tag, __VA_ARGS__)
759
760#define android_vprintLog(prio, cond, tag, ...) \
761 __android_log_vprint(prio, tag, __VA_ARGS__)
762
763/* XXX Macros to work around syntax errors in places where format string
764 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
765 * (happens only in debug builds).
766 */
767
768/* Returns 2nd arg. Used to substitute default value if caller's vararg list
769 * is empty.
770 */
771#define __android_second(dummy, second, ...) second
772
773/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
774 * returns nothing.
775 */
776#define __android_rest(first, ...) , ## __VA_ARGS__
777
778#define android_printAssert(cond, tag, ...) \
779 __android_log_assert(cond, tag, \
780 __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__))
781
782#define android_writeLog(prio, tag, text) \
783 __android_log_write(prio, tag, text)
784
785#define android_bWriteLog(tag, payload, len) \
786 __android_log_bwrite(tag, payload, len)
787#define android_btWriteLog(tag, type, payload, len) \
788 __android_log_btwrite(tag, type, payload, len)
789
790#define android_errorWriteLog(tag, subTag) \
791 __android_log_error_write(tag, subTag, -1, NULL, 0)
792
793#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
794 __android_log_error_write(tag, subTag, uid, data, dataLen)
795
796/*
797 * IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
798 * android_testLog will remain constant in its purpose as a wrapper
799 * for Android logging filter policy, and can be subject to
800 * change. It can be reused by the developers that override
801 * IF_ALOG as a convenient means to reimplement their policy
802 * over Android.
803 */
804#if LOG_NDEBUG /* Production */
805#define android_testLog(prio, tag) \
806 (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
807#else
808#define android_testLog(prio, tag) \
809 (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
810#endif
811
812/*
813 * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
814 * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
815 * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
816 * any other value.
817 */
818int __android_log_is_loggable(int prio, const char *tag, int default_prio);
819
820int __android_log_security(); /* Device Owner is present */
821
822int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
823 uint32_t dataLen);
824
825/*
826 * Send a simple string to the log.
827 */
828int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
829int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
830#if defined(__GNUC__)
831 __attribute__((__format__(printf, 4, 5)))
832#endif
833 ;
834
835#if defined(__clang__)
836#pragma clang diagnostic pop
837#endif
838
145#ifdef __cplusplus 839#ifdef __cplusplus
146} 840}
147#endif 841#endif
diff --git a/include/log/log.h b/include/log/log.h
index 4e65393e7..ffb826893 100644
--- a/include/log/log.h
+++ b/include/log/log.h
@@ -1,721 +1 @@
1/*
2 * Copyright (C) 2005-2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//
18// C/C++ logging functions. See the logging documentation for API details.
19//
20// We'd like these to be available from C code (in case we import some from
21// somewhere), so this has a C interface.
22//
23// The output will be correct when the log file is shared between multiple
24// threads and/or multiple processes so long as the operating system
25// supports O_APPEND. These calls have mutex-protected data structures
26// and so are NOT reentrant. Do not use LOG in a signal handler.
27//
28#ifndef _LIBS_LOG_LOG_H
29#define _LIBS_LOG_LOG_H
30
31#include <stdarg.h>
32#include <stdint.h>
33#include <stdio.h>
34#include <sys/types.h>
35#include <time.h>
36#include <unistd.h>
37
38#include <android/log.h> #include <android/log.h>
39#include <log/uio.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45// This file uses ", ## __VA_ARGS__" zero-argument token pasting to
46// work around issues with debug-only syntax errors in assertions
47// that are missing format strings. See commit
48// 19299904343daf191267564fe32e6cd5c165cd42
49#if defined(__clang__)
50#pragma clang diagnostic push
51#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
52#endif
53
54int __android_log_bwrite(int32_t tag, const void *payload, size_t len);
55int __android_log_btwrite(int32_t tag, char type, const void *payload,
56 size_t len);
57int __android_log_bswrite(int32_t tag, const char *payload);
58
59int __android_log_security_bwrite(int32_t tag, const void *payload, size_t len);
60int __android_log_security_bswrite(int32_t tag, const char *payload);
61
62// ---------------------------------------------------------------------
63
64/*
65 * Normally we strip ALOGV (VERBOSE messages) from release builds.
66 * You can modify this (for example with "#define LOG_NDEBUG 0"
67 * at the top of your source file) to change that behavior.
68 */
69#ifndef LOG_NDEBUG
70#ifdef NDEBUG
71#define LOG_NDEBUG 1
72#else
73#define LOG_NDEBUG 0
74#endif
75#endif
76
77/*
78 * This is the local tag used for the following simplified
79 * logging macros. You can change this preprocessor definition
80 * before using the other macros to change the tag.
81 */
82#ifndef LOG_TAG
83#define LOG_TAG NULL
84#endif
85
86// ---------------------------------------------------------------------
87
88#ifndef __predict_false
89#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
90#endif
91
92/*
93 * -DLINT_RLOG in sources that you want to enforce that all logging
94 * goes to the radio log buffer. If any logging goes to any of the other
95 * log buffers, there will be a compile or link error to highlight the
96 * problem. This is not a replacement for a full audit of the code since
97 * this only catches compiled code, not ifdef'd debug code. Options to
98 * defining this, either temporarily to do a spot check, or permanently
99 * to enforce, in all the communications trees; We have hopes to ensure
100 * that by supplying just the radio log buffer that the communications
101 * teams will have their one-stop shop for triaging issues.
102 */
103#ifndef LINT_RLOG
104
105/*
106 * Simplified macro to send a verbose log message using the current LOG_TAG.
107 */
108#ifndef ALOGV
109#define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
110#if LOG_NDEBUG
111#define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0)
112#else
113#define ALOGV(...) __ALOGV(__VA_ARGS__)
114#endif
115#endif
116
117#ifndef ALOGV_IF
118#if LOG_NDEBUG
119#define ALOGV_IF(cond, ...) ((void)0)
120#else
121#define ALOGV_IF(cond, ...) \
122 ( (__predict_false(cond)) \
123 ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
124 : (void)0 )
125#endif
126#endif
127
128/*
129 * Simplified macro to send a debug log message using the current LOG_TAG.
130 */
131#ifndef ALOGD
132#define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
133#endif
134
135#ifndef ALOGD_IF
136#define ALOGD_IF(cond, ...) \
137 ( (__predict_false(cond)) \
138 ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
139 : (void)0 )
140#endif
141
142/*
143 * Simplified macro to send an info log message using the current LOG_TAG.
144 */
145#ifndef ALOGI
146#define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
147#endif
148
149#ifndef ALOGI_IF
150#define ALOGI_IF(cond, ...) \
151 ( (__predict_false(cond)) \
152 ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \
153 : (void)0 )
154#endif
155
156/*
157 * Simplified macro to send a warning log message using the current LOG_TAG.
158 */
159#ifndef ALOGW
160#define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
161#endif
162
163#ifndef ALOGW_IF
164#define ALOGW_IF(cond, ...) \
165 ( (__predict_false(cond)) \
166 ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \
167 : (void)0 )
168#endif
169
170/*
171 * Simplified macro to send an error log message using the current LOG_TAG.
172 */
173#ifndef ALOGE
174#define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
175#endif
176
177#ifndef ALOGE_IF
178#define ALOGE_IF(cond, ...) \
179 ( (__predict_false(cond)) \
180 ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
181 : (void)0 )
182#endif
183
184// ---------------------------------------------------------------------
185
186/*
187 * Conditional based on whether the current LOG_TAG is enabled at
188 * verbose priority.
189 */
190#ifndef IF_ALOGV
191#if LOG_NDEBUG
192#define IF_ALOGV() if (false)
193#else
194#define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG)
195#endif
196#endif
197
198/*
199 * Conditional based on whether the current LOG_TAG is enabled at
200 * debug priority.
201 */
202#ifndef IF_ALOGD
203#define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG)
204#endif
205
206/*
207 * Conditional based on whether the current LOG_TAG is enabled at
208 * info priority.
209 */
210#ifndef IF_ALOGI
211#define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG)
212#endif
213
214/*
215 * Conditional based on whether the current LOG_TAG is enabled at
216 * warn priority.
217 */
218#ifndef IF_ALOGW
219#define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG)
220#endif
221
222/*
223 * Conditional based on whether the current LOG_TAG is enabled at
224 * error priority.
225 */
226#ifndef IF_ALOGE
227#define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG)
228#endif
229
230
231// ---------------------------------------------------------------------
232
233/*
234 * Simplified macro to send a verbose system log message using the current LOG_TAG.
235 */
236#ifndef SLOGV
237#define __SLOGV(...) \
238 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
239#if LOG_NDEBUG
240#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
241#else
242#define SLOGV(...) __SLOGV(__VA_ARGS__)
243#endif
244#endif
245
246#ifndef SLOGV_IF
247#if LOG_NDEBUG
248#define SLOGV_IF(cond, ...) ((void)0)
249#else
250#define SLOGV_IF(cond, ...) \
251 ( (__predict_false(cond)) \
252 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
253 : (void)0 )
254#endif
255#endif
256
257/*
258 * Simplified macro to send a debug system log message using the current LOG_TAG.
259 */
260#ifndef SLOGD
261#define SLOGD(...) \
262 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
263#endif
264
265#ifndef SLOGD_IF
266#define SLOGD_IF(cond, ...) \
267 ( (__predict_false(cond)) \
268 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
269 : (void)0 )
270#endif
271
272/*
273 * Simplified macro to send an info system log message using the current LOG_TAG.
274 */
275#ifndef SLOGI
276#define SLOGI(...) \
277 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
278#endif
279
280#ifndef SLOGI_IF
281#define SLOGI_IF(cond, ...) \
282 ( (__predict_false(cond)) \
283 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
284 : (void)0 )
285#endif
286
287/*
288 * Simplified macro to send a warning system log message using the current LOG_TAG.
289 */
290#ifndef SLOGW
291#define SLOGW(...) \
292 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
293#endif
294
295#ifndef SLOGW_IF
296#define SLOGW_IF(cond, ...) \
297 ( (__predict_false(cond)) \
298 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
299 : (void)0 )
300#endif
301
302/*
303 * Simplified macro to send an error system log message using the current LOG_TAG.
304 */
305#ifndef SLOGE
306#define SLOGE(...) \
307 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
308#endif
309
310#ifndef SLOGE_IF
311#define SLOGE_IF(cond, ...) \
312 ( (__predict_false(cond)) \
313 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
314 : (void)0 )
315#endif
316
317#endif /* !LINT_RLOG */
318
319// ---------------------------------------------------------------------
320
321/*
322 * Simplified macro to send a verbose radio log message using the current LOG_TAG.
323 */
324#ifndef RLOGV
325#define __RLOGV(...) \
326 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
327#if LOG_NDEBUG
328#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
329#else
330#define RLOGV(...) __RLOGV(__VA_ARGS__)
331#endif
332#endif
333
334#ifndef RLOGV_IF
335#if LOG_NDEBUG
336#define RLOGV_IF(cond, ...) ((void)0)
337#else
338#define RLOGV_IF(cond, ...) \
339 ( (__predict_false(cond)) \
340 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
341 : (void)0 )
342#endif
343#endif
344
345/*
346 * Simplified macro to send a debug radio log message using the current LOG_TAG.
347 */
348#ifndef RLOGD
349#define RLOGD(...) \
350 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
351#endif
352
353#ifndef RLOGD_IF
354#define RLOGD_IF(cond, ...) \
355 ( (__predict_false(cond)) \
356 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
357 : (void)0 )
358#endif
359
360/*
361 * Simplified macro to send an info radio log message using the current LOG_TAG.
362 */
363#ifndef RLOGI
364#define RLOGI(...) \
365 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
366#endif
367
368#ifndef RLOGI_IF
369#define RLOGI_IF(cond, ...) \
370 ( (__predict_false(cond)) \
371 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
372 : (void)0 )
373#endif
374
375/*
376 * Simplified macro to send a warning radio log message using the current LOG_TAG.
377 */
378#ifndef RLOGW
379#define RLOGW(...) \
380 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
381#endif
382
383#ifndef RLOGW_IF
384#define RLOGW_IF(cond, ...) \
385 ( (__predict_false(cond)) \
386 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
387 : (void)0 )
388#endif
389
390/*
391 * Simplified macro to send an error radio log message using the current LOG_TAG.
392 */
393#ifndef RLOGE
394#define RLOGE(...) \
395 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
396#endif
397
398#ifndef RLOGE_IF
399#define RLOGE_IF(cond, ...) \
400 ( (__predict_false(cond)) \
401 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
402 : (void)0 )
403#endif
404
405
406// ---------------------------------------------------------------------
407
408/*
409 * Log a fatal error. If the given condition fails, this stops program
410 * execution like a normal assertion, but also generating the given message.
411 * It is NOT stripped from release builds. Note that the condition test
412 * is -inverted- from the normal assert() semantics.
413 */
414#ifndef LOG_ALWAYS_FATAL_IF
415#define LOG_ALWAYS_FATAL_IF(cond, ...) \
416 ( (__predict_false(cond)) \
417 ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \
418 : (void)0 )
419#endif
420
421#ifndef LOG_ALWAYS_FATAL
422#define LOG_ALWAYS_FATAL(...) \
423 ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) )
424#endif
425
426/*
427 * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that
428 * are stripped out of release builds.
429 */
430#if LOG_NDEBUG
431
432#ifndef LOG_FATAL_IF
433#define LOG_FATAL_IF(cond, ...) ((void)0)
434#endif
435#ifndef LOG_FATAL
436#define LOG_FATAL(...) ((void)0)
437#endif
438
439#else
440
441#ifndef LOG_FATAL_IF
442#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__)
443#endif
444#ifndef LOG_FATAL
445#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__)
446#endif
447
448#endif
449
450/*
451 * Assertion that generates a log message when the assertion fails.
452 * Stripped out of release builds. Uses the current LOG_TAG.
453 */
454#ifndef ALOG_ASSERT
455#define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__)
456//#define ALOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond)
457#endif
458
459// ---------------------------------------------------------------------
460
461/*
462 * Basic log message macro.
463 *
464 * Example:
465 * ALOG(LOG_WARN, NULL, "Failed with error %d", errno);
466 *
467 * The second argument may be NULL or "" to indicate the "global" tag.
468 */
469#ifndef ALOG
470#define ALOG(priority, tag, ...) \
471 LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__)
472#endif
473
474/*
475 * Log macro that allows you to specify a number for the priority.
476 */
477#ifndef LOG_PRI
478#define LOG_PRI(priority, tag, ...) \
479 android_printLog(priority, tag, __VA_ARGS__)
480#endif
481
482/*
483 * Log macro that allows you to pass in a varargs ("args" is a va_list).
484 */
485#ifndef LOG_PRI_VA
486#define LOG_PRI_VA(priority, tag, fmt, args) \
487 android_vprintLog(priority, NULL, tag, fmt, args)
488#endif
489
490/*
491 * Conditional given a desired logging priority and tag.
492 */
493#ifndef IF_ALOG
494#define IF_ALOG(priority, tag) \
495 if (android_testLog(ANDROID_##priority, tag))
496#endif
497
498// ---------------------------------------------------------------------
499
500/*
501 * Event logging.
502 */
503
504/*
505 * Event log entry types.
506 */
507typedef enum {
508 /* Special markers for android_log_list_element type */
509 EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
510 EVENT_TYPE_UNKNOWN = '?', /* protocol error */
511
512 /* must match with declaration in java/android/android/util/EventLog.java */
513 EVENT_TYPE_INT = 0, /* uint32_t */
514 EVENT_TYPE_LONG = 1, /* uint64_t */
515 EVENT_TYPE_STRING = 2,
516 EVENT_TYPE_LIST = 3,
517 EVENT_TYPE_FLOAT = 4,
518} AndroidEventLogType;
519#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
520#define typeof_AndroidEventLogType unsigned char
521
522#ifndef LOG_EVENT_INT
523#define LOG_EVENT_INT(_tag, _value) { \
524 int intBuf = _value; \
525 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
526 sizeof(intBuf)); \
527 }
528#endif
529#ifndef LOG_EVENT_LONG
530#define LOG_EVENT_LONG(_tag, _value) { \
531 long long longBuf = _value; \
532 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
533 sizeof(longBuf)); \
534 }
535#endif
536#ifndef LOG_EVENT_FLOAT
537#define LOG_EVENT_FLOAT(_tag, _value) { \
538 float floatBuf = _value; \
539 (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
540 sizeof(floatBuf)); \
541 }
542#endif
543#ifndef LOG_EVENT_STRING
544#define LOG_EVENT_STRING(_tag, _value) \
545 (void) __android_log_bswrite(_tag, _value);
546#endif
547
548typedef enum log_id {
549 LOG_ID_MIN = 0,
550
551#ifndef LINT_RLOG
552 LOG_ID_MAIN = 0,
553#endif
554 LOG_ID_RADIO = 1,
555#ifndef LINT_RLOG
556 LOG_ID_EVENTS = 2,
557 LOG_ID_SYSTEM = 3,
558 LOG_ID_CRASH = 4,
559 LOG_ID_SECURITY = 5,
560 LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
561#endif
562
563 LOG_ID_MAX
564} log_id_t;
565#define sizeof_log_id_t sizeof(typeof_log_id_t)
566#define typeof_log_id_t unsigned char
567
568/* For manipulating lists of events. */
569
570#define ANDROID_MAX_LIST_NEST_DEPTH 8
571
572/*
573 * The opaque context used to manipulate lists of events.
574 */
575typedef struct android_log_context_internal *android_log_context;
576
577/*
578 * Elements returned when reading a list of events.
579 */
580typedef struct {
581 AndroidEventLogType type;
582 uint16_t complete;
583 uint16_t len;
584 union {
585 int32_t int32;
586 int64_t int64;
587 char *string;
588 float float32;
589 } data;
590} android_log_list_element;
591
592/*
593 * Creates a context associated with an event tag to write elements to
594 * the list of events.
595 */
596android_log_context create_android_logger(uint32_t tag);
597
598/* All lists must be braced by a begin and end call */
599/*
600 * NB: If the first level braces are missing when specifying multiple
601 * elements, we will manufacturer a list to embrace it for your API
602 * convenience. For a single element, it will remain solitary.
603 */
604int android_log_write_list_begin(android_log_context ctx);
605int android_log_write_list_end(android_log_context ctx);
606
607int android_log_write_int32(android_log_context ctx, int32_t value);
608int android_log_write_int64(android_log_context ctx, int64_t value);
609int android_log_write_string8(android_log_context ctx, const char *value);
610int android_log_write_string8_len(android_log_context ctx,
611 const char *value, size_t maxlen);
612int android_log_write_float32(android_log_context ctx, float value);
613
614/* Submit the composed list context to the specified logger id */
615/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
616int android_log_write_list(android_log_context ctx, log_id_t id);
617
618/*
619 * Creates a context from a raw buffer representing a list of events to be read.
620 */
621android_log_context create_android_log_parser(const char *msg, size_t len);
622
623android_log_list_element android_log_read_next(android_log_context ctx);
624android_log_list_element android_log_peek_next(android_log_context ctx);
625
626/* Finished with reader or writer context */
627int android_log_destroy(android_log_context *ctx);
628
629/*
630 * ===========================================================================
631 *
632 * The stuff in the rest of this file should not be used directly.
633 */
634
635#define android_printLog(prio, tag, ...) \
636 __android_log_print(prio, tag, __VA_ARGS__)
637
638#define android_vprintLog(prio, cond, tag, ...) \
639 __android_log_vprint(prio, tag, __VA_ARGS__)
640
641/* XXX Macros to work around syntax errors in places where format string
642 * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF
643 * (happens only in debug builds).
644 */
645
646/* Returns 2nd arg. Used to substitute default value if caller's vararg list
647 * is empty.
648 */
649#define __android_second(dummy, second, ...) second
650
651/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise
652 * returns nothing.
653 */
654#define __android_rest(first, ...) , ## __VA_ARGS__
655
656#define android_printAssert(cond, tag, ...) \
657 __android_log_assert(cond, tag, \
658 __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__))
659
660#define android_writeLog(prio, tag, text) \
661 __android_log_write(prio, tag, text)
662
663#define android_bWriteLog(tag, payload, len) \
664 __android_log_bwrite(tag, payload, len)
665#define android_btWriteLog(tag, type, payload, len) \
666 __android_log_btwrite(tag, type, payload, len)
667
668#define android_errorWriteLog(tag, subTag) \
669 __android_log_error_write(tag, subTag, -1, NULL, 0)
670
671#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
672 __android_log_error_write(tag, subTag, uid, data, dataLen)
673
674/*
675 * IF_ALOG uses android_testLog, but IF_ALOG can be overridden.
676 * android_testLog will remain constant in its purpose as a wrapper
677 * for Android logging filter policy, and can be subject to
678 * change. It can be reused by the developers that override
679 * IF_ALOG as a convenient means to reimplement their policy
680 * over Android.
681 */
682#if LOG_NDEBUG /* Production */
683#define android_testLog(prio, tag) \
684 (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0)
685#else
686#define android_testLog(prio, tag) \
687 (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0)
688#endif
689
690/*
691 * Use the per-tag properties "log.tag.<tagname>" to generate a runtime
692 * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to
693 * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if
694 * any other value.
695 */
696int __android_log_is_loggable(int prio, const char *tag, int default_prio);
697
698int __android_log_security(); /* Device Owner is present */
699
700int __android_log_error_write(int tag, const char *subTag, int32_t uid, const char *data,
701 uint32_t dataLen);
702
703/*
704 * Send a simple string to the log.
705 */
706int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
707int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
708#if defined(__GNUC__)
709 __attribute__((__format__(printf, 4, 5)))
710#endif
711 ;
712
713#if defined(__clang__)
714#pragma clang diagnostic pop
715#endif
716
717#ifdef __cplusplus
718}
719#endif
720
721#endif /* _LIBS_LOG_LOG_H */
diff --git a/include/log/logd.h b/include/log/logd.h
index 0e0248e50..ffb826893 100644
--- a/include/log/logd.h
+++ b/include/log/logd.h
@@ -1 +1 @@
#include <log/log.h> #include <android/log.h>
diff --git a/include/log/logger.h b/include/log/logger.h
index 65b38de8d..46587fb74 100644
--- a/include/log/logger.h
+++ b/include/log/logger.h
@@ -17,7 +17,7 @@
17#include <string> 17#include <string>
18#endif 18#endif
19 19
20#include <log/log.h> 20#include <android/log.h>
21 21
22#ifdef __cplusplus 22#ifdef __cplusplus
23extern "C" { 23extern "C" {
diff --git a/include/log/logprint.h b/include/log/logprint.h
index 1bc1f7241..45230cd6a 100644
--- a/include/log/logprint.h
+++ b/include/log/logprint.h
@@ -17,7 +17,7 @@
17#ifndef _LOGPRINT_H 17#ifndef _LOGPRINT_H
18#define _LOGPRINT_H 18#define _LOGPRINT_H
19 19
20#include <log/log.h> 20#include <android/log.h>
21#include <log/logger.h> 21#include <log/logger.h>
22#include <log/event_tag_map.h> 22#include <log/event_tag_map.h>
23#include <pthread.h> 23#include <pthread.h>
diff --git a/include/private/android_logger.h b/include/private/android_logger.h
index 52ddade65..b6a20c305 100644
--- a/include/private/android_logger.h
+++ b/include/private/android_logger.h
@@ -24,7 +24,7 @@
24#include <stdint.h> 24#include <stdint.h>
25#include <sys/types.h> 25#include <sys/types.h>
26 26
27#include <log/log.h> 27#include <android/log.h>
28#include <log/logger.h> 28#include <log/logger.h>
29 29
30#define LOGGER_MAGIC 'l' 30#define LOGGER_MAGIC 'l'
diff --git a/liblog/README b/liblog/README
index df1e68c65..eefa80fef 100644
--- a/liblog/README
+++ b/liblog/README
@@ -6,7 +6,7 @@ NAME
6 liblog - Android NDK logger interfaces 6 liblog - Android NDK logger interfaces
7 7
8SYNOPSIS 8SYNOPSIS
9 #include <log/log.h> 9 #include <android/log.h>
10 10
11 ALOG(android_priority, tag, format, ...) 11 ALOG(android_priority, tag, format, ...)
12 IF_ALOG(android_priority, tag) 12 IF_ALOG(android_priority, tag)
diff --git a/liblog/event_tag_map.c b/liblog/event_tag_map.c
index c8943e0ce..c2dc74cd4 100644
--- a/liblog/event_tag_map.c
+++ b/liblog/event_tag_map.c
@@ -23,8 +23,8 @@
23#include <string.h> 23#include <string.h>
24#include <sys/mman.h> 24#include <sys/mman.h>
25 25
26#include <android/log.h>
26#include <log/event_tag_map.h> 27#include <log/event_tag_map.h>
27#include <log/log.h>
28 28
29#include "log_portability.h" 29#include "log_portability.h"
30 30
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index 8e5df3dad..1b57e7550 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -28,7 +28,7 @@
28#include <stdlib.h> 28#include <stdlib.h>
29#include <string.h> 29#include <string.h>
30 30
31#include <log/log.h> 31#include <android/log.h>
32 32
33#include "fake_log_device.h" 33#include "fake_log_device.h"
34#include "log_portability.h" 34#include "log_portability.h"
diff --git a/liblog/fake_writer.c b/liblog/fake_writer.c
index dab8bc54e..47935e35d 100644
--- a/liblog/fake_writer.c
+++ b/liblog/fake_writer.c
@@ -18,7 +18,7 @@
18#include <fcntl.h> 18#include <fcntl.h>
19#include <unistd.h> 19#include <unistd.h>
20 20
21#include <log/log.h> 21#include <android/log.h>
22 22
23#include "config_write.h" 23#include "config_write.h"
24#include "fake_log_device.h" 24#include "fake_log_device.h"
diff --git a/liblog/log_event_list.c b/liblog/log_event_list.c
index 64d9024c6..a4244cd05 100644
--- a/liblog/log_event_list.c
+++ b/liblog/log_event_list.c
@@ -22,7 +22,7 @@
22#include <stdlib.h> 22#include <stdlib.h>
23#include <string.h> 23#include <string.h>
24 24
25#include <log/log.h> 25#include <android/log.h>
26#include <log/logger.h> 26#include <log/logger.h>
27 27
28#include "log_portability.h" 28#include "log_portability.h"
diff --git a/liblog/log_event_write.c b/liblog/log_event_write.c
index b9827a16d..8c8a9a1fe 100644
--- a/liblog/log_event_write.c
+++ b/liblog/log_event_write.c
@@ -16,7 +16,7 @@
16 16
17#include <errno.h> 17#include <errno.h>
18 18
19#include <log/log.h> 19#include <android/log.h>
20 20
21#include "log_portability.h" 21#include "log_portability.h"
22 22
diff --git a/liblog/logd_reader.c b/liblog/logd_reader.c
index d796ecd23..563b5c750 100644
--- a/liblog/logd_reader.c
+++ b/liblog/logd_reader.c
@@ -31,8 +31,8 @@
31#include <time.h> 31#include <time.h>
32#include <unistd.h> 32#include <unistd.h>
33 33
34#include <android/log.h>
34#include <cutils/sockets.h> 35#include <cutils/sockets.h>
35#include <log/log.h>
36#include <log/logger.h> 36#include <log/logger.h>
37#include <private/android_filesystem_config.h> 37#include <private/android_filesystem_config.h>
38#include <private/android_logger.h> 38#include <private/android_logger.h>
diff --git a/liblog/logd_writer.c b/liblog/logd_writer.c
index 40ad48d53..ebf8b3e46 100644
--- a/liblog/logd_writer.c
+++ b/liblog/logd_writer.c
@@ -31,8 +31,8 @@
31#include <time.h> 31#include <time.h>
32#include <unistd.h> 32#include <unistd.h>
33 33
34#include <android/log.h>
34#include <cutils/sockets.h> 35#include <cutils/sockets.h>
35#include <log/log.h>
36#include <log/logger.h> 36#include <log/logger.h>
37#include <private/android_filesystem_config.h> 37#include <private/android_filesystem_config.h>
38#include <private/android_logger.h> 38#include <private/android_logger.h>
diff --git a/liblog/logger.h b/liblog/logger.h
index 8367f445e..8fb2b4d47 100644
--- a/liblog/logger.h
+++ b/liblog/logger.h
@@ -20,8 +20,8 @@
20#include <stdbool.h> 20#include <stdbool.h>
21#include <log/uio.h> 21#include <log/uio.h>
22 22
23#include <android/log.h>
23#include <cutils/list.h> 24#include <cutils/list.h>
24#include <log/log.h>
25#include <log/logger.h> 25#include <log/logger.h>
26 26
27#include "log_portability.h" 27#include "log_portability.h"
diff --git a/liblog/logger_name.c b/liblog/logger_name.c
index b7ccac51f..12e263a04 100644
--- a/liblog/logger_name.c
+++ b/liblog/logger_name.c
@@ -16,7 +16,7 @@
16 16
17#include <string.h> 17#include <string.h>
18 18
19#include <log/log.h> 19#include <android/log.h>
20#include <log/logger.h> 20#include <log/logger.h>
21 21
22#include "log_portability.h" 22#include "log_portability.h"
diff --git a/liblog/logger_read.c b/liblog/logger_read.c
index 0d5545302..d979e22e9 100644
--- a/liblog/logger_read.c
+++ b/liblog/logger_read.c
@@ -23,8 +23,8 @@
23#include <string.h> 23#include <string.h>
24#include <unistd.h> 24#include <unistd.h>
25 25
26#include <android/log.h>
26#include <cutils/list.h> 27#include <cutils/list.h>
27#include <log/log.h>
28#include <log/logger.h> 28#include <log/logger.h>
29#include <private/android_filesystem_config.h> 29#include <private/android_filesystem_config.h>
30 30
diff --git a/liblog/logger_write.c b/liblog/logger_write.c
index 583b79977..4999aef0d 100644
--- a/liblog/logger_write.c
+++ b/liblog/logger_write.c
@@ -24,8 +24,8 @@
24#include <android/set_abort_message.h> 24#include <android/set_abort_message.h>
25#endif 25#endif
26 26
27#include <android/log.h>
27#include <log/event_tag_map.h> 28#include <log/event_tag_map.h>
28#include <log/log.h>
29#include <log/logger.h> 29#include <log/logger.h>
30#include <private/android_filesystem_config.h> 30#include <private/android_filesystem_config.h>
31#include <private/android_logger.h> 31#include <private/android_logger.h>
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 668b2ff0b..d857090ef 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -31,8 +31,8 @@
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/types.h> 32#include <sys/types.h>
33 33
34#include <android/log.h>
34#include <cutils/list.h> 35#include <cutils/list.h>
35#include <log/log.h>
36#include <log/logprint.h> 36#include <log/logprint.h>
37 37
38#include "log_portability.h" 38#include "log_portability.h"
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c
index 944febae8..06652f3c1 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.c
@@ -25,7 +25,7 @@
25#include <sys/types.h> 25#include <sys/types.h>
26#include <time.h> 26#include <time.h>
27 27
28#include <log/log.h> 28#include <android/log.h>
29#include <log/logger.h> 29#include <log/logger.h>
30 30
31#include <private/android_filesystem_config.h> 31#include <private/android_filesystem_config.h>
diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp
index 22404d180..7561d8f0d 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -20,8 +20,8 @@
20#include <sys/types.h> 20#include <sys/types.h>
21#include <unistd.h> 21#include <unistd.h>
22 22
23#include <android/log.h>
23#include <cutils/sockets.h> 24#include <cutils/sockets.h>
24#include <log/log.h>
25#include <log/logger.h> 25#include <log/logger.h>
26#include <private/android_logger.h> 26#include <private/android_logger.h>
27 27
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index cb9a5223f..6e709a948 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -22,9 +22,9 @@
22#include <sys/types.h> 22#include <sys/types.h>
23#include <unistd.h> 23#include <unistd.h>
24 24
25#include <android/log.h>
25#include <cutils/properties.h> 26#include <cutils/properties.h>
26#include <gtest/gtest.h> 27#include <gtest/gtest.h>
27#include <log/log.h>
28#include <log/logger.h> 28#include <log/logger.h>
29#include <log/logprint.h> 29#include <log/logprint.h>
30#include <private/android_filesystem_config.h> 30#include <private/android_filesystem_config.h>