summaryrefslogtreecommitdiffstats
path: root/liblog
diff options
context:
space:
mode:
authorVijay Venkatraman2017-01-05 12:22:52 -0600
committerVijay Venkatraman2017-01-22 21:45:38 -0600
commit3c6763ca21c1150d66daf8fde9b440b1c3219fe6 (patch)
tree7a8df02f4d5f95e86faa96886f77e21e61eba4e1 /liblog
parent41ee55a8754f12389394c0266c05d09123707f77 (diff)
downloadplatform-system-core-3c6763ca21c1150d66daf8fde9b440b1c3219fe6.tar.gz
platform-system-core-3c6763ca21c1150d66daf8fde9b440b1c3219fe6.tar.xz
platform-system-core-3c6763ca21c1150d66daf8fde9b440b1c3219fe6.zip
Exporting C headers from system/core
Moved headers from include/libcutils and include/liblog to libcutils/include and liblog/include respectively, so they can be exported via these libs. They needed to be moved since Soong does not allow export from external folder. Added symlink from old locations. They are needed since Soong includes system/core/include by default. Once all modules are cleaned up to explicitly add the required libs, the symlinks will be removed. Also added liblog_vndk_headers that exports a special log/log.h for VNDK. Moved headers of libcutils to libcutils_headers. They should be used by modules for header-only inlines. Added libcutils_headers as dependency of libcutils. Added libcutils_vndk_headers that exports a special cutils/log.h deprecating usage of the file. A later CL will deprecate the one in libcutils_headers Test: Add above libs to shared lib of local module Change-Id: I6e1f9c5f23d8b6eae13dc3b7e5dfe7fae93b8510
Diffstat (limited to 'liblog')
-rw-r--r--liblog/Android.bp7
-rw-r--r--liblog/include/log/event_tag_map.h65
-rw-r--r--liblog/include/log/log.h871
-rw-r--r--liblog/include/log/log_event_list.h297
-rw-r--r--liblog/include/log/logd.h5
-rw-r--r--liblog/include/log/logger.h5
-rw-r--r--liblog/include/log/logprint.h163
-rw-r--r--liblog/include/log/uio.h51
-rw-r--r--liblog/include/private/android_logger.h194
l---------liblog/include_vndk/android1
-rw-r--r--liblog/include_vndk/log/log.h22
11 files changed, 1681 insertions, 0 deletions
diff --git a/liblog/Android.bp b/liblog/Android.bp
index bbe7d793e..dd0a77816 100644
--- a/liblog/Android.bp
+++ b/liblog/Android.bp
@@ -79,6 +79,8 @@ cc_library {
79 }, 79 },
80 }, 80 },
81 81
82 export_include_dirs: ["include"],
83
82 cflags: [ 84 cflags: [
83 "-Werror", 85 "-Werror",
84 "-fvisibility=hidden", 86 "-fvisibility=hidden",
@@ -111,6 +113,11 @@ ndk_headers {
111 license: "NOTICE", 113 license: "NOTICE",
112} 114}
113 115
116cc_library_headers {
117 name: "liblog_vndk_headers",
118 export_include_dirs: ["include_vndk"],
119}
120
114ndk_library { 121ndk_library {
115 name: "liblog.ndk", 122 name: "liblog.ndk",
116 symbol_file: "liblog.map.txt", 123 symbol_file: "liblog.map.txt",
diff --git a/liblog/include/log/event_tag_map.h b/liblog/include/log/event_tag_map.h
new file mode 100644
index 000000000..22e62ec98
--- /dev/null
+++ b/liblog/include/log/event_tag_map.h
@@ -0,0 +1,65 @@
1/*
2 * Copyright (C) 2007 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 _LIBS_CUTILS_EVENTTAGMAP_H
18#define _LIBS_CUTILS_EVENTTAGMAP_H
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#define EVENT_TAG_MAP_FILE "/system/etc/event-log-tags"
25
26struct EventTagMap;
27typedef struct EventTagMap EventTagMap;
28
29/*
30 * Open the specified file as an event log tag map.
31 *
32 * Returns NULL on failure.
33 */
34EventTagMap* android_openEventTagMap(const char* fileName);
35
36/*
37 * Close the map.
38 */
39void android_closeEventTagMap(EventTagMap* map);
40
41/*
42 * Look up a tag by index. Returns the tag string, or NULL if not found.
43 */
44const char* android_lookupEventTag(const EventTagMap* map, unsigned int tag)
45 __attribute__((deprecated("use android_lookupEventTag_len() instead to minimize MAP_PRIVATE copy-on-write memory impact")));
46
47/*
48 * Look up a tag by index. Returns the tag string & string length, or NULL if
49 * not found. Returned string is not guaranteed to be nul terminated.
50 */
51const char* android_lookupEventTag_len(const EventTagMap* map,
52 size_t* len, unsigned int tag);
53
54/*
55 * Look up a format by index. Returns the format string & string length,
56 * or NULL if not found. Returned string is not guaranteed to be nul terminated.
57 */
58const char* android_lookupEventFormat_len(const EventTagMap* map,
59 size_t* len, unsigned int tag);
60
61#ifdef __cplusplus
62}
63#endif
64
65#endif /*_LIBS_CUTILS_EVENTTAGMAP_H*/
diff --git a/liblog/include/log/log.h b/liblog/include/log/log.h
new file mode 100644
index 000000000..ece9ea6d1
--- /dev/null
+++ b/liblog/include/log/log.h
@@ -0,0 +1,871 @@
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#ifndef _LIBS_LOG_LOG_H
18#define _LIBS_LOG_LOG_H
19
20/* Too many in the ecosystem assume these are included */
21#if !defined(_WIN32)
22#include <pthread.h>
23#endif
24#include <stdint.h> /* uint16_t, int32_t */
25#include <stdio.h>
26#include <sys/types.h>
27#include <time.h>
28#include <unistd.h>
29
30#include <android/log.h>
31#include <log/uio.h> /* helper to define iovec for portability */
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/*
38 * LOG_TAG is the local tag used for the following simplified
39 * logging macros. You can change this preprocessor definition
40 * before using the other macros to change the tag.
41 */
42
43#ifndef LOG_TAG
44#define LOG_TAG NULL
45#endif
46
47/* --------------------------------------------------------------------- */
48
49/*
50 * This file uses ", ## __VA_ARGS__" zero-argument token pasting to
51 * work around issues with debug-only syntax errors in assertions
52 * that are missing format strings. See commit
53 * 19299904343daf191267564fe32e6cd5c165cd42
54 */
55#if defined(__clang__)
56#pragma clang diagnostic push
57#pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
58#endif
59
60/*
61 * Send a simple string to the log.
62 */
63int __android_log_buf_write(int bufID, int prio, const char* tag, const char* text);
64int __android_log_buf_print(int bufID, int prio, const char* tag, const char* fmt, ...)
65#if defined(__GNUC__)
66 __attribute__((__format__(printf, 4, 5)))
67#endif
68 ;
69
70/*
71 * Simplified macro to send a verbose system log message using current LOG_TAG.
72 */
73#ifndef SLOGV
74#define __SLOGV(...) \
75 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
76#if LOG_NDEBUG
77#define SLOGV(...) do { if (0) { __SLOGV(__VA_ARGS__); } } while (0)
78#else
79#define SLOGV(...) __SLOGV(__VA_ARGS__)
80#endif
81#endif
82
83#ifndef SLOGV_IF
84#if LOG_NDEBUG
85#define SLOGV_IF(cond, ...) ((void)0)
86#else
87#define SLOGV_IF(cond, ...) \
88 ( (__predict_false(cond)) \
89 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
90 : (void)0 )
91#endif
92#endif
93
94/*
95 * Simplified macro to send a debug system log message using current LOG_TAG.
96 */
97#ifndef SLOGD
98#define SLOGD(...) \
99 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
100#endif
101
102#ifndef SLOGD_IF
103#define SLOGD_IF(cond, ...) \
104 ( (__predict_false(cond)) \
105 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
106 : (void)0 )
107#endif
108
109/*
110 * Simplified macro to send an info system log message using current LOG_TAG.
111 */
112#ifndef SLOGI
113#define SLOGI(...) \
114 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
115#endif
116
117#ifndef SLOGI_IF
118#define SLOGI_IF(cond, ...) \
119 ( (__predict_false(cond)) \
120 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
121 : (void)0 )
122#endif
123
124/*
125 * Simplified macro to send a warning system log message using current LOG_TAG.
126 */
127#ifndef SLOGW
128#define SLOGW(...) \
129 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
130#endif
131
132#ifndef SLOGW_IF
133#define SLOGW_IF(cond, ...) \
134 ( (__predict_false(cond)) \
135 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
136 : (void)0 )
137#endif
138
139/*
140 * Simplified macro to send an error system log message using current LOG_TAG.
141 */
142#ifndef SLOGE
143#define SLOGE(...) \
144 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
145#endif
146
147#ifndef SLOGE_IF
148#define SLOGE_IF(cond, ...) \
149 ( (__predict_false(cond)) \
150 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
151 : (void)0 )
152#endif
153
154/* --------------------------------------------------------------------- */
155
156/*
157 * Simplified macro to send a verbose radio log message using current LOG_TAG.
158 */
159#ifndef RLOGV
160#define __RLOGV(...) \
161 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
162#if LOG_NDEBUG
163#define RLOGV(...) do { if (0) { __RLOGV(__VA_ARGS__); } } while (0)
164#else
165#define RLOGV(...) __RLOGV(__VA_ARGS__)
166#endif
167#endif
168
169#ifndef RLOGV_IF
170#if LOG_NDEBUG
171#define RLOGV_IF(cond, ...) ((void)0)
172#else
173#define RLOGV_IF(cond, ...) \
174 ( (__predict_false(cond)) \
175 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
176 : (void)0 )
177#endif
178#endif
179
180/*
181 * Simplified macro to send a debug radio log message using current LOG_TAG.
182 */
183#ifndef RLOGD
184#define RLOGD(...) \
185 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
186#endif
187
188#ifndef RLOGD_IF
189#define RLOGD_IF(cond, ...) \
190 ( (__predict_false(cond)) \
191 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
192 : (void)0 )
193#endif
194
195/*
196 * Simplified macro to send an info radio log message using current LOG_TAG.
197 */
198#ifndef RLOGI
199#define RLOGI(...) \
200 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
201#endif
202
203#ifndef RLOGI_IF
204#define RLOGI_IF(cond, ...) \
205 ( (__predict_false(cond)) \
206 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
207 : (void)0 )
208#endif
209
210/*
211 * Simplified macro to send a warning radio log message using current LOG_TAG.
212 */
213#ifndef RLOGW
214#define RLOGW(...) \
215 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
216#endif
217
218#ifndef RLOGW_IF
219#define RLOGW_IF(cond, ...) \
220 ( (__predict_false(cond)) \
221 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
222 : (void)0 )
223#endif
224
225/*
226 * Simplified macro to send an error radio log message using current LOG_TAG.
227 */
228#ifndef RLOGE
229#define RLOGE(...) \
230 ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
231#endif
232
233#ifndef RLOGE_IF
234#define RLOGE_IF(cond, ...) \
235 ( (__predict_false(cond)) \
236 ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
237 : (void)0 )
238#endif
239
240/* --------------------------------------------------------------------- */
241
242/*
243 * Event logging.
244 */
245
246/*
247 * The following should not be used directly.
248 */
249
250int __android_log_bwrite(int32_t tag, const void* payload, size_t len);
251int __android_log_btwrite(int32_t tag, char type, const void* payload,
252 size_t len);
253int __android_log_bswrite(int32_t tag, const char* payload);
254
255#define android_bWriteLog(tag, payload, len) \
256 __android_log_bwrite(tag, payload, len)
257#define android_btWriteLog(tag, type, payload, len) \
258 __android_log_btwrite(tag, type, payload, len)
259
260/*
261 * Event log entry types.
262 */
263#ifndef __AndroidEventLogType_defined
264#define __AndroidEventLogType_defined
265typedef enum {
266 /* Special markers for android_log_list_element type */
267 EVENT_TYPE_LIST_STOP = '\n', /* declare end of list */
268 EVENT_TYPE_UNKNOWN = '?', /* protocol error */
269
270 /* must match with declaration in java/android/android/util/EventLog.java */
271 EVENT_TYPE_INT = 0, /* int32_t */
272 EVENT_TYPE_LONG = 1, /* int64_t */
273 EVENT_TYPE_STRING = 2,
274 EVENT_TYPE_LIST = 3,
275 EVENT_TYPE_FLOAT = 4,
276} AndroidEventLogType;
277#endif
278#define sizeof_AndroidEventLogType sizeof(typeof_AndroidEventLogType)
279#define typeof_AndroidEventLogType unsigned char
280
281#ifndef LOG_EVENT_INT
282#define LOG_EVENT_INT(_tag, _value) { \
283 int intBuf = _value; \
284 (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \
285 sizeof(intBuf)); \
286 }
287#endif
288#ifndef LOG_EVENT_LONG
289#define LOG_EVENT_LONG(_tag, _value) { \
290 long long longBuf = _value; \
291 (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \
292 sizeof(longBuf)); \
293 }
294#endif
295#ifndef LOG_EVENT_FLOAT
296#define LOG_EVENT_FLOAT(_tag, _value) { \
297 float floatBuf = _value; \
298 (void) android_btWriteLog(_tag, EVENT_TYPE_FLOAT, &floatBuf, \
299 sizeof(floatBuf)); \
300 }
301#endif
302#ifndef LOG_EVENT_STRING
303#define LOG_EVENT_STRING(_tag, _value) \
304 (void) __android_log_bswrite(_tag, _value);
305#endif
306
307#ifndef log_id_t_defined
308#define log_id_t_defined
309typedef enum log_id {
310 LOG_ID_MIN = 0,
311
312 LOG_ID_MAIN = 0,
313 LOG_ID_RADIO = 1,
314 LOG_ID_EVENTS = 2,
315 LOG_ID_SYSTEM = 3,
316 LOG_ID_CRASH = 4,
317 LOG_ID_SECURITY = 5,
318 LOG_ID_KERNEL = 6, /* place last, third-parties can not use it */
319
320 LOG_ID_MAX
321} log_id_t;
322#endif
323#define sizeof_log_id_t sizeof(typeof_log_id_t)
324#define typeof_log_id_t unsigned char
325
326/* --------------------------------------------------------------------- */
327
328/*
329 * Native log reading interface section. See logcat for sample code.
330 *
331 * The preferred API is an exec of logcat. Likely uses of this interface
332 * are if native code suffers from exec or filtration being too costly,
333 * access to raw information, or parsing is an issue.
334 */
335
336/*
337 * The userspace structure for version 1 of the logger_entry ABI.
338 */
339#ifndef __struct_logger_entry_defined
340#define __struct_logger_entry_defined
341struct logger_entry {
342 uint16_t len; /* length of the payload */
343 uint16_t __pad; /* no matter what, we get 2 bytes of padding */
344 int32_t pid; /* generating process's pid */
345 int32_t tid; /* generating process's tid */
346 int32_t sec; /* seconds since Epoch */
347 int32_t nsec; /* nanoseconds */
348#ifndef __cplusplus
349 char msg[0]; /* the entry's payload */
350#endif
351};
352#endif
353
354/*
355 * The userspace structure for version 2 of the logger_entry ABI.
356 */
357#ifndef __struct_logger_entry_v2_defined
358#define __struct_logger_entry_v2_defined
359struct logger_entry_v2 {
360 uint16_t len; /* length of the payload */
361 uint16_t hdr_size; /* sizeof(struct logger_entry_v2) */
362 int32_t pid; /* generating process's pid */
363 int32_t tid; /* generating process's tid */
364 int32_t sec; /* seconds since Epoch */
365 int32_t nsec; /* nanoseconds */
366 uint32_t euid; /* effective UID of logger */
367#ifndef __cplusplus
368 char msg[0]; /* the entry's payload */
369#endif
370} __attribute__((__packed__));
371#endif
372
373/*
374 * The userspace structure for version 3 of the logger_entry ABI.
375 */
376#ifndef __struct_logger_entry_v3_defined
377#define __struct_logger_entry_v3_defined
378struct logger_entry_v3 {
379 uint16_t len; /* length of the payload */
380 uint16_t hdr_size; /* sizeof(struct logger_entry_v3) */
381 int32_t pid; /* generating process's pid */
382 int32_t tid; /* generating process's tid */
383 int32_t sec; /* seconds since Epoch */
384 int32_t nsec; /* nanoseconds */
385 uint32_t lid; /* log id of the payload */
386#ifndef __cplusplus
387 char msg[0]; /* the entry's payload */
388#endif
389} __attribute__((__packed__));
390#endif
391
392/*
393 * The userspace structure for version 4 of the logger_entry ABI.
394 */
395#ifndef __struct_logger_entry_v4_defined
396#define __struct_logger_entry_v4_defined
397struct logger_entry_v4 {
398 uint16_t len; /* length of the payload */
399 uint16_t hdr_size; /* sizeof(struct logger_entry_v4) */
400 int32_t pid; /* generating process's pid */
401 uint32_t tid; /* generating process's tid */
402 uint32_t sec; /* seconds since Epoch */
403 uint32_t nsec; /* nanoseconds */
404 uint32_t lid; /* log id of the payload, bottom 4 bits currently */
405 uint32_t uid; /* generating process's uid */
406#ifndef __cplusplus
407 char msg[0]; /* the entry's payload */
408#endif
409};
410#endif
411
412/* struct log_time is a wire-format variant of struct timespec */
413#define NS_PER_SEC 1000000000ULL
414
415#ifndef __struct_log_time_defined
416#define __struct_log_time_defined
417#ifdef __cplusplus
418
419/*
420 * NB: we did NOT define a copy constructor. This will result in structure
421 * no longer being compatible with pass-by-value which is desired
422 * efficient behavior. Also, pass-by-reference breaks C/C++ ABI.
423 */
424struct log_time {
425public:
426 uint32_t tv_sec; /* good to Feb 5 2106 */
427 uint32_t tv_nsec;
428
429 static const uint32_t tv_sec_max = 0xFFFFFFFFUL;
430 static const uint32_t tv_nsec_max = 999999999UL;
431
432 log_time(const timespec& T)
433 {
434 tv_sec = static_cast<uint32_t>(T.tv_sec);
435 tv_nsec = static_cast<uint32_t>(T.tv_nsec);
436 }
437 log_time(uint32_t sec, uint32_t nsec)
438 {
439 tv_sec = sec;
440 tv_nsec = nsec;
441 }
442#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
443#define __struct_log_time_private_defined
444 static const timespec EPOCH;
445#endif
446 log_time()
447 {
448 }
449#ifdef __linux__
450 log_time(clockid_t id)
451 {
452 timespec T;
453 clock_gettime(id, &T);
454 tv_sec = static_cast<uint32_t>(T.tv_sec);
455 tv_nsec = static_cast<uint32_t>(T.tv_nsec);
456 }
457#endif
458 log_time(const char* T)
459 {
460 const uint8_t* c = reinterpret_cast<const uint8_t*>(T);
461 tv_sec = c[0] |
462 (static_cast<uint32_t>(c[1]) << 8) |
463 (static_cast<uint32_t>(c[2]) << 16) |
464 (static_cast<uint32_t>(c[3]) << 24);
465 tv_nsec = c[4] |
466 (static_cast<uint32_t>(c[5]) << 8) |
467 (static_cast<uint32_t>(c[6]) << 16) |
468 (static_cast<uint32_t>(c[7]) << 24);
469 }
470
471 /* timespec */
472 bool operator== (const timespec& T) const
473 {
474 return (tv_sec == static_cast<uint32_t>(T.tv_sec))
475 && (tv_nsec == static_cast<uint32_t>(T.tv_nsec));
476 }
477 bool operator!= (const timespec& T) const
478 {
479 return !(*this == T);
480 }
481 bool operator< (const timespec& T) const
482 {
483 return (tv_sec < static_cast<uint32_t>(T.tv_sec))
484 || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
485 && (tv_nsec < static_cast<uint32_t>(T.tv_nsec)));
486 }
487 bool operator>= (const timespec& T) const
488 {
489 return !(*this < T);
490 }
491 bool operator> (const timespec& T) const
492 {
493 return (tv_sec > static_cast<uint32_t>(T.tv_sec))
494 || ((tv_sec == static_cast<uint32_t>(T.tv_sec))
495 && (tv_nsec > static_cast<uint32_t>(T.tv_nsec)));
496 }
497 bool operator<= (const timespec& T) const
498 {
499 return !(*this > T);
500 }
501
502#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
503 log_time operator-= (const timespec& T);
504 log_time operator- (const timespec& T) const
505 {
506 log_time local(*this);
507 return local -= T;
508 }
509 log_time operator+= (const timespec& T);
510 log_time operator+ (const timespec& T) const
511 {
512 log_time local(*this);
513 return local += T;
514 }
515#endif
516
517 /* log_time */
518 bool operator== (const log_time& T) const
519 {
520 return (tv_sec == T.tv_sec) && (tv_nsec == T.tv_nsec);
521 }
522 bool operator!= (const log_time& T) const
523 {
524 return !(*this == T);
525 }
526 bool operator< (const log_time& T) const
527 {
528 return (tv_sec < T.tv_sec)
529 || ((tv_sec == T.tv_sec) && (tv_nsec < T.tv_nsec));
530 }
531 bool operator>= (const log_time& T) const
532 {
533 return !(*this < T);
534 }
535 bool operator> (const log_time& T) const
536 {
537 return (tv_sec > T.tv_sec)
538 || ((tv_sec == T.tv_sec) && (tv_nsec > T.tv_nsec));
539 }
540 bool operator<= (const log_time& T) const
541 {
542 return !(*this > T);
543 }
544
545#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
546 log_time operator-= (const log_time& T);
547 log_time operator- (const log_time& T) const
548 {
549 log_time local(*this);
550 return local -= T;
551 }
552 log_time operator+= (const log_time& T);
553 log_time operator+ (const log_time& T) const
554 {
555 log_time local(*this);
556 return local += T;
557 }
558#endif
559
560 uint64_t nsec() const
561 {
562 return static_cast<uint64_t>(tv_sec) * NS_PER_SEC + tv_nsec;
563 }
564
565#ifdef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
566 static const char default_format[];
567
568 /* Add %#q for the fraction of a second to the standard library functions */
569 char* strptime(const char* s, const char* format = default_format);
570#endif
571} __attribute__((__packed__));
572
573#else
574
575typedef struct log_time {
576 uint32_t tv_sec;
577 uint32_t tv_nsec;
578} __attribute__((__packed__)) log_time;
579
580#endif
581#endif
582
583/*
584 * The maximum size of the log entry payload that can be
585 * written to the logger. An attempt to write more than
586 * this amount will result in a truncated log entry.
587 */
588#define LOGGER_ENTRY_MAX_PAYLOAD 4068
589
590/*
591 * The maximum size of a log entry which can be read from the
592 * kernel logger driver. An attempt to read less than this amount
593 * may result in read() returning EINVAL.
594 */
595#define LOGGER_ENTRY_MAX_LEN (5*1024)
596
597#ifndef __struct_log_msg_defined
598#define __struct_log_msg_defined
599struct log_msg {
600 union {
601 unsigned char buf[LOGGER_ENTRY_MAX_LEN + 1];
602 struct logger_entry_v4 entry;
603 struct logger_entry_v4 entry_v4;
604 struct logger_entry_v3 entry_v3;
605 struct logger_entry_v2 entry_v2;
606 struct logger_entry entry_v1;
607 } __attribute__((aligned(4)));
608#ifdef __cplusplus
609 /* Matching log_time operators */
610 bool operator== (const log_msg& T) const
611 {
612 return (entry.sec == T.entry.sec) && (entry.nsec == T.entry.nsec);
613 }
614 bool operator!= (const log_msg& T) const
615 {
616 return !(*this == T);
617 }
618 bool operator< (const log_msg& T) const
619 {
620 return (entry.sec < T.entry.sec)
621 || ((entry.sec == T.entry.sec)
622 && (entry.nsec < T.entry.nsec));
623 }
624 bool operator>= (const log_msg& T) const
625 {
626 return !(*this < T);
627 }
628 bool operator> (const log_msg& T) const
629 {
630 return (entry.sec > T.entry.sec)
631 || ((entry.sec == T.entry.sec)
632 && (entry.nsec > T.entry.nsec));
633 }
634 bool operator<= (const log_msg& T) const
635 {
636 return !(*this > T);
637 }
638 uint64_t nsec() const
639 {
640 return static_cast<uint64_t>(entry.sec) * NS_PER_SEC + entry.nsec;
641 }
642
643 /* packet methods */
644 log_id_t id()
645 {
646 return static_cast<log_id_t>(entry.lid);
647 }
648 char* msg()
649 {
650 unsigned short hdr_size = entry.hdr_size;
651 if (!hdr_size) {
652 hdr_size = sizeof(entry_v1);
653 }
654 if ((hdr_size < sizeof(entry_v1)) || (hdr_size > sizeof(entry))) {
655 return NULL;
656 }
657 return reinterpret_cast<char*>(buf) + hdr_size;
658 }
659 unsigned int len()
660 {
661 return (entry.hdr_size ?
662 entry.hdr_size :
663 static_cast<uint16_t>(sizeof(entry_v1))) +
664 entry.len;
665 }
666#endif
667};
668#endif
669
670#ifndef __ANDROID_USE_LIBLOG_READER_INTERFACE
671#ifndef __ANDROID_API__
672#define __ANDROID_USE_LIBLOG_READER_INTERFACE 3
673#elif __ANDROID_API__ > 23 /* > Marshmallow */
674#define __ANDROID_USE_LIBLOG_READER_INTERFACE 3
675#elif __ANDROID_API__ > 22 /* > Lollipop */
676#define __ANDROID_USE_LIBLOG_READER_INTERFACE 2
677#elif __ANDROID_API__ > 19 /* > KitKat */
678#define __ANDROID_USE_LIBLOG_READER_INTERFACE 1
679#else
680#define __ANDROID_USE_LIBLOG_READER_INTERFACE 0
681#endif
682#endif
683
684#if __ANDROID_USE_LIBLOG_READER_INTERFACE
685
686struct logger;
687
688log_id_t android_logger_get_id(struct logger* logger);
689
690int android_logger_clear(struct logger* logger);
691long android_logger_get_log_size(struct logger* logger);
692int android_logger_set_log_size(struct logger* logger, unsigned long size);
693long android_logger_get_log_readable_size(struct logger* logger);
694int android_logger_get_log_version(struct logger* logger);
695
696struct logger_list;
697
698#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 1
699ssize_t android_logger_get_statistics(struct logger_list* logger_list,
700 char* buf, size_t len);
701ssize_t android_logger_get_prune_list(struct logger_list* logger_list,
702 char* buf, size_t len);
703int android_logger_set_prune_list(struct logger_list* logger_list,
704 char* buf, size_t len);
705#endif
706
707#define ANDROID_LOG_RDONLY O_RDONLY
708#define ANDROID_LOG_WRONLY O_WRONLY
709#define ANDROID_LOG_RDWR O_RDWR
710#define ANDROID_LOG_ACCMODE O_ACCMODE
711#define ANDROID_LOG_NONBLOCK O_NONBLOCK
712#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 2
713#define ANDROID_LOG_WRAP 0x40000000 /* Block until buffer about to wrap */
714#define ANDROID_LOG_WRAP_DEFAULT_TIMEOUT 7200 /* 2 hour default */
715#endif
716#if __ANDROID_USE_LIBLOG_READER_INTERFACE > 1
717#define ANDROID_LOG_PSTORE 0x80000000
718#endif
719
720struct logger_list* android_logger_list_alloc(int mode,
721 unsigned int tail,
722 pid_t pid);
723struct logger_list* android_logger_list_alloc_time(int mode,
724 log_time start,
725 pid_t pid);
726void android_logger_list_free(struct logger_list* logger_list);
727/* In the purest sense, the following two are orthogonal interfaces */
728int android_logger_list_read(struct logger_list* logger_list,
729 struct log_msg* log_msg);
730
731/* Multiple log_id_t opens */
732struct logger* android_logger_open(struct logger_list* logger_list,
733 log_id_t id);
734#define android_logger_close android_logger_free
735/* Single log_id_t open */
736struct logger_list* android_logger_list_open(log_id_t id,
737 int mode,
738 unsigned int tail,
739 pid_t pid);
740#define android_logger_list_close android_logger_list_free
741
742#endif /* __ANDROID_USE_LIBLOG_READER_INTERFACE */
743
744#ifdef __linux__
745
746#ifndef __ANDROID_USE_LIBLOG_CLOCK_INTERFACE
747#ifndef __ANDROID_API__
748#define __ANDROID_USE_LIBLOG_CLOCK_INTERFACE 1
749#elif __ANDROID_API__ > 22 /* > Lollipop */
750#define __ANDROID_USE_LIBLOG_CLOCK_INTERFACE 1
751#else
752#define __ANDROID_USE_LIBLOG_CLOCK_INTERFACE 0
753#endif
754#endif
755
756#if __ANDROID_USE_LIBLOG_CLOCK_INTERFACE
757clockid_t android_log_clockid();
758#endif
759
760#endif /* __linux__ */
761
762/*
763 * log_id_t helpers
764 */
765log_id_t android_name_to_log_id(const char* logName);
766const char* android_log_id_to_name(log_id_t log_id);
767
768/* --------------------------------------------------------------------- */
769
770#ifndef _ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
771#ifndef __ANDROID_API__
772#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
773#elif __ANDROID_API__ > 22 /* > Lollipop */
774#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 1
775#else
776#define __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE 0
777#endif
778#endif
779
780#if __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE
781
782#define android_errorWriteLog(tag, subTag) \
783 __android_log_error_write(tag, subTag, -1, NULL, 0)
784
785#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \
786 __android_log_error_write(tag, subTag, uid, data, dataLen)
787
788int __android_log_error_write(int tag, const char* subTag, int32_t uid,
789 const char* data, uint32_t dataLen);
790
791#endif /* __ANDROID_USE_LIBLOG_SAFETYNET_INTERFACE */
792
793/* --------------------------------------------------------------------- */
794
795#ifndef __ANDROID_USE_LIBLOG_CLOSE_INTERFACE
796#ifndef __ANDROID_API__
797#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 1
798#elif __ANDROID_API__ > 18 /* > JellyBean */
799#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 1
800#else
801#define __ANDROID_USE_LIBLOG_CLOSE_INTERFACE 0
802#endif
803#endif
804
805#if __ANDROID_USE_LIBLOG_CLOSE_INTERFACE
806/*
807 * Release any logger resources (a new log write will immediately re-acquire)
808 *
809 * May be used to clean up File descriptors after a Fork, the resources are
810 * all O_CLOEXEC so wil self clean on exec().
811 */
812void __android_log_close();
813#endif
814
815#ifndef __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE
816#ifndef __ANDROID_API__
817#define __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE 1
818#elif __ANDROID_API__ > 25 /* > OC */
819#define __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE 1
820#else
821#define __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE 0
822#endif
823#endif
824
825#if __ANDROID_USE_LIBLOG_RATELIMIT_INTERFACE
826
827/*
828 * if last is NULL, caller _must_ provide a consistent value for seconds.
829 *
830 * Return -1 if we can not acquire a lock, which below will permit the logging,
831 * error on allowing a log message through.
832 */
833int __android_log_ratelimit(time_t seconds, time_t* last);
834
835/*
836 * Usage:
837 *
838 * // Global default and state
839 * IF_ALOG_RATELIMIT() {
840 * ALOG*(...);
841 * }
842 *
843 * // local state, 10 seconds ratelimit
844 * static time_t local_state;
845 * IF_ALOG_RATELIMIT_LOCAL(10, &local_state) {
846 * ALOG*(...);
847 * }
848 */
849
850#define IF_ALOG_RATELIMIT() \
851 if (__android_log_ratelimit(0, NULL) > 0)
852#define IF_ALOG_RATELIMIT_LOCAL(seconds, state) \
853 if (__android_log_ratelimit(seconds, state) > 0)
854
855#else
856
857/* No ratelimiting as API unsupported */
858#define IF_ALOG_RATELIMIT() if (1)
859#define IF_ALOG_RATELIMIT_LOCAL(...) if (1)
860
861#endif
862
863#if defined(__clang__)
864#pragma clang diagnostic pop
865#endif
866
867#ifdef __cplusplus
868}
869#endif
870
871#endif /* _LIBS_LOG_LOG_H */
diff --git a/liblog/include/log/log_event_list.h b/liblog/include/log/log_event_list.h
new file mode 100644
index 000000000..31d49b2f9
--- /dev/null
+++ b/liblog/include/log/log_event_list.h
@@ -0,0 +1,297 @@
1/*
2 * Copyright (C) 2005-2016 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 _LIBS_LOG_EVENT_LIST_H
18#define _LIBS_LOG_EVENT_LIST_H
19
20#include <stdint.h>
21
22#if (defined(__cplusplus) && defined(_USING_LIBCXX))
23extern "C++" {
24#include <string>
25}
26#endif
27
28#include <log/log.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#ifndef __ANDROID_USE_LIBLOG_EVENT_INTERFACE
35#ifndef __ANDROID_API__
36#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
37#elif __ANDROID_API__ > 23 /* > Marshmallow */
38#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 1
39#else
40#define __ANDROID_USE_LIBLOG_EVENT_INTERFACE 0
41#endif
42#endif
43
44#if __ANDROID_USE_LIBLOG_EVENT_INTERFACE
45
46/* For manipulating lists of events. */
47
48#define ANDROID_MAX_LIST_NEST_DEPTH 8
49
50/*
51 * The opaque context used to manipulate lists of events.
52 */
53#ifndef __android_log_context_defined
54#define __android_log_context_defined
55typedef struct android_log_context_internal* android_log_context;
56#endif
57
58/*
59 * Elements returned when reading a list of events.
60 */
61#ifndef __android_log_list_element_defined
62#define __android_log_list_element_defined
63typedef struct {
64 AndroidEventLogType type;
65 uint16_t complete;
66 uint16_t len;
67 union {
68 int32_t int32;
69 int64_t int64;
70 char* string;
71 float float32;
72 } data;
73} android_log_list_element;
74#endif
75
76/*
77 * Creates a context associated with an event tag to write elements to
78 * the list of events.
79 */
80android_log_context create_android_logger(uint32_t tag);
81
82/* All lists must be braced by a begin and end call */
83/*
84 * NB: If the first level braces are missing when specifying multiple
85 * elements, we will manufacturer a list to embrace it for your API
86 * convenience. For a single element, it will remain solitary.
87 */
88int android_log_write_list_begin(android_log_context ctx);
89int android_log_write_list_end(android_log_context ctx);
90
91int android_log_write_int32(android_log_context ctx, int32_t value);
92int android_log_write_int64(android_log_context ctx, int64_t value);
93int android_log_write_string8(android_log_context ctx, const char* value);
94int android_log_write_string8_len(android_log_context ctx,
95 const char* value, size_t maxlen);
96int android_log_write_float32(android_log_context ctx, float value);
97
98/* Submit the composed list context to the specified logger id */
99/* NB: LOG_ID_EVENTS and LOG_ID_SECURITY only valid binary buffers */
100int android_log_write_list(android_log_context ctx, log_id_t id);
101
102/*
103 * Creates a context from a raw buffer representing a list of events to be read.
104 */
105android_log_context create_android_log_parser(const char* msg, size_t len);
106
107android_log_list_element android_log_read_next(android_log_context ctx);
108android_log_list_element android_log_peek_next(android_log_context ctx);
109
110/* Finished with reader or writer context */
111int android_log_destroy(android_log_context* ctx);
112
113#ifdef __cplusplus
114#ifndef __class_android_log_event_list_defined
115#define __class_android_log_event_list_defined
116/* android_log_list C++ helpers */
117extern "C++" {
118class android_log_event_list {
119friend class __android_log_event_list;
120
121private:
122 android_log_context ctx;
123 int ret;
124
125 android_log_event_list(const android_log_event_list&) = delete;
126 void operator =(const android_log_event_list&) = delete;
127
128public:
129 explicit android_log_event_list(int tag) : ret(0) {
130 ctx = create_android_logger(static_cast<uint32_t>(tag));
131 }
132 explicit android_log_event_list(log_msg& log_msg) : ret(0) {
133 ctx = create_android_log_parser(log_msg.msg() + sizeof(uint32_t),
134 log_msg.entry.len - sizeof(uint32_t));
135 }
136 ~android_log_event_list() { android_log_destroy(&ctx); }
137
138 int close() {
139 int retval = android_log_destroy(&ctx);
140 if (retval < 0) ret = retval;
141 return retval;
142 }
143
144 /* To allow above C calls to use this class as parameter */
145 operator android_log_context() const { return ctx; }
146
147 int status() const { return ret; }
148
149 int begin() {
150 int retval = android_log_write_list_begin(ctx);
151 if (retval < 0) ret = retval;
152 return ret;
153 }
154 int end() {
155 int retval = android_log_write_list_end(ctx);
156 if (retval < 0) ret = retval;
157 return ret;
158 }
159
160 android_log_event_list& operator <<(int32_t value) {
161 int retval = android_log_write_int32(ctx, value);
162 if (retval < 0) ret = retval;
163 return *this;
164 }
165
166 android_log_event_list& operator <<(uint32_t value) {
167 int retval = android_log_write_int32(ctx, static_cast<int32_t>(value));
168 if (retval < 0) ret = retval;
169 return *this;
170 }
171
172 android_log_event_list& operator <<(int64_t value) {
173 int retval = android_log_write_int64(ctx, value);
174 if (retval < 0) ret = retval;
175 return *this;
176 }
177
178 android_log_event_list& operator <<(uint64_t value) {
179 int retval = android_log_write_int64(ctx, static_cast<int64_t>(value));
180 if (retval < 0) ret = retval;
181 return *this;
182 }
183
184 android_log_event_list& operator <<(const char* value) {
185 int retval = android_log_write_string8(ctx, value);
186 if (retval < 0) ret = retval;
187 return *this;
188 }
189
190#if defined(_USING_LIBCXX)
191 android_log_event_list& operator <<(const std::string& value) {
192 int retval = android_log_write_string8_len(ctx,
193 value.data(),
194 value.length());
195 if (retval < 0) ret = retval;
196 return *this;
197 }
198#endif
199
200 android_log_event_list& operator <<(float value) {
201 int retval = android_log_write_float32(ctx, value);
202 if (retval < 0) ret = retval;
203 return *this;
204 }
205
206 int write(log_id_t id = LOG_ID_EVENTS) {
207 int retval = android_log_write_list(ctx, id);
208 if (retval < 0) ret = retval;
209 return ret;
210 }
211
212 int operator <<(log_id_t id) {
213 int retval = android_log_write_list(ctx, id);
214 if (retval < 0) ret = retval;
215 android_log_destroy(&ctx);
216 return ret;
217 }
218
219 /*
220 * Append<Type> methods removes any integer promotion
221 * confusion, and adds access to string with length.
222 * Append methods are also added for all types for
223 * convenience.
224 */
225
226 bool AppendInt(int32_t value) {
227 int retval = android_log_write_int32(ctx, value);
228 if (retval < 0) ret = retval;
229 return ret >= 0;
230 }
231
232 bool AppendLong(int64_t value) {
233 int retval = android_log_write_int64(ctx, value);
234 if (retval < 0) ret = retval;
235 return ret >= 0;
236 }
237
238 bool AppendString(const char* value) {
239 int retval = android_log_write_string8(ctx, value);
240 if (retval < 0) ret = retval;
241 return ret >= 0;
242 }
243
244 bool AppendString(const char* value, size_t len) {
245 int retval = android_log_write_string8_len(ctx, value, len);
246 if (retval < 0) ret = retval;
247 return ret >= 0;
248 }
249
250#if defined(_USING_LIBCXX)
251 bool AppendString(const std::string& value) {
252 int retval = android_log_write_string8_len(ctx,
253 value.data(),
254 value.length());
255 if (retval < 0) ret = retval;
256 return ret;
257 }
258
259 bool Append(const std::string& value) {
260 int retval = android_log_write_string8_len(ctx,
261 value.data(),
262 value.length());
263 if (retval < 0) ret = retval;
264 return ret;
265 }
266#endif
267
268 bool AppendFloat(float value) {
269 int retval = android_log_write_float32(ctx, value);
270 if (retval < 0) ret = retval;
271 return ret >= 0;
272 }
273
274 template <typename Tvalue>
275 bool Append(Tvalue value) { *this << value; return ret >= 0; }
276
277 bool Append(const char* value, size_t len) {
278 int retval = android_log_write_string8_len(ctx, value, len);
279 if (retval < 0) ret = retval;
280 return ret >= 0;
281 }
282
283 android_log_list_element read() { return android_log_read_next(ctx); }
284 android_log_list_element peek() { return android_log_peek_next(ctx); }
285
286};
287}
288#endif
289#endif
290
291#endif /* __ANDROID_USE_LIBLOG_EVENT_INTERFACE */
292
293#ifdef __cplusplus
294}
295#endif
296
297#endif /* _LIBS_LOG_EVENT_LIST_H */
diff --git a/liblog/include/log/logd.h b/liblog/include/log/logd.h
new file mode 100644
index 000000000..77400cad3
--- /dev/null
+++ b/liblog/include/log/logd.h
@@ -0,0 +1,5 @@
1#ifndef _LIBS_LOG_LOGD_H
2#define _LIBS_LOG_LOGD_H
3#include <log/log.h>
4#warning "Deprecated: do not include log/logd.h, use log/log.h instead"
5#endif /*_LIBS_LOG_LOGD_H*/
diff --git a/liblog/include/log/logger.h b/liblog/include/log/logger.h
new file mode 100644
index 000000000..1bf2d1746
--- /dev/null
+++ b/liblog/include/log/logger.h
@@ -0,0 +1,5 @@
1#ifndef _LIBS_LOG_LOGGER_H
2#define _LIBS_LOG_LOGGER_H
3#include <log/log.h>
4#warning "Deprecated: do not include log/logger.h, use log/log.h instead"
5#endif /*_LIBS_LOG_LOGGER_H*/
diff --git a/liblog/include/log/logprint.h b/liblog/include/log/logprint.h
new file mode 100644
index 000000000..3509e7f51
--- /dev/null
+++ b/liblog/include/log/logprint.h
@@ -0,0 +1,163 @@
1/*
2 * Copyright (C) 2006 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 _LOGPRINT_H
18#define _LOGPRINT_H
19
20#include <pthread.h>
21
22#include <android/log.h>
23#include <log/event_tag_map.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29typedef enum {
30 /* Verbs */
31 FORMAT_OFF = 0,
32 FORMAT_BRIEF,
33 FORMAT_PROCESS,
34 FORMAT_TAG,
35 FORMAT_THREAD,
36 FORMAT_RAW,
37 FORMAT_TIME,
38 FORMAT_THREADTIME,
39 FORMAT_LONG,
40 /* Adverbs. The following are modifiers to above format verbs */
41 FORMAT_MODIFIER_COLOR, /* converts priority to color */
42 FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
43 FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */
44 FORMAT_MODIFIER_YEAR, /* Adds year to date */
45 FORMAT_MODIFIER_ZONE, /* Adds zone to date */
46 FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */
47 FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
48 FORMAT_MODIFIER_UID, /* Adds uid */
49 FORMAT_MODIFIER_DESCRIPT, /* Adds descriptive */
50} AndroidLogPrintFormat;
51
52typedef struct AndroidLogFormat_t AndroidLogFormat;
53
54typedef struct AndroidLogEntry_t {
55 time_t tv_sec;
56 long tv_nsec;
57 android_LogPriority priority;
58 int32_t uid;
59 int32_t pid;
60 int32_t tid;
61 const char* tag;
62 size_t tagLen;
63 size_t messageLen;
64 const char* message;
65} AndroidLogEntry;
66
67AndroidLogFormat* android_log_format_new();
68
69void android_log_format_free(AndroidLogFormat* p_format);
70
71/* currently returns 0 if format is a modifier, 1 if not */
72int android_log_setPrintFormat(AndroidLogFormat* p_format,
73 AndroidLogPrintFormat format);
74
75/**
76 * Returns FORMAT_OFF on invalid string
77 */
78AndroidLogPrintFormat android_log_formatFromString(const char* s);
79
80/**
81 * filterExpression: a single filter expression
82 * eg "AT:d"
83 *
84 * returns 0 on success and -1 on invalid expression
85 *
86 * Assumes single threaded execution
87 *
88 */
89
90int android_log_addFilterRule(AndroidLogFormat* p_format,
91 const char* filterExpression);
92
93/**
94 * filterString: a whitespace-separated set of filter expressions
95 * eg "AT:d *:i"
96 *
97 * returns 0 on success and -1 on invalid expression
98 *
99 * Assumes single threaded execution
100 *
101 */
102
103int android_log_addFilterString(AndroidLogFormat* p_format,
104 const char* filterString);
105
106/**
107 * returns 1 if this log line should be printed based on its priority
108 * and tag, and 0 if it should not
109 */
110int android_log_shouldPrintLine (
111 AndroidLogFormat* p_format, const char* tag, android_LogPriority pri);
112
113/**
114 * Splits a wire-format buffer into an AndroidLogEntry
115 * entry allocated by caller. Pointers will point directly into buf
116 *
117 * Returns 0 on success and -1 on invalid wire format (entry will be
118 * in unspecified state)
119 */
120int android_log_processLogBuffer(struct logger_entry* buf,
121 AndroidLogEntry* entry);
122
123/**
124 * Like android_log_processLogBuffer, but for binary logs.
125 *
126 * If "map" is non-NULL, it will be used to convert the log tag number
127 * into a string.
128 */
129int android_log_processBinaryLogBuffer(struct logger_entry* buf,
130 AndroidLogEntry* entry, const EventTagMap* map, char* messageBuf,
131 int messageBufLen);
132
133/**
134 * Formats a log message into a buffer
135 *
136 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
137 * If return value != defaultBuffer, caller must call free()
138 * Returns NULL on malloc error
139 */
140
141char* android_log_formatLogLine (
142 AndroidLogFormat* p_format,
143 char* defaultBuffer,
144 size_t defaultBufferSize,
145 const AndroidLogEntry* p_line,
146 size_t* p_outLength);
147
148/**
149 * Either print or do not print log line, based on filter
150 *
151 * Assumes single threaded execution
152 *
153 */
154int android_log_printLogLine(
155 AndroidLogFormat* p_format,
156 int fd,
157 const AndroidLogEntry* entry);
158
159#ifdef __cplusplus
160}
161#endif
162
163#endif /*_LOGPRINT_H*/
diff --git a/liblog/include/log/uio.h b/liblog/include/log/uio.h
new file mode 100644
index 000000000..7059da5f7
--- /dev/null
+++ b/liblog/include/log/uio.h
@@ -0,0 +1,51 @@
1/*
2 * Copyright (C) 2007-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#ifndef _LIBS_CUTILS_UIO_H
18#define _LIBS_CUTILS_UIO_H
19
20#if !defined(_WIN32)
21
22#include <sys/uio.h>
23
24#else
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30//
31// Implementation of sys/uio.h for Win32.
32//
33
34#include <stddef.h>
35
36struct iovec {
37 void* iov_base;
38 size_t iov_len;
39};
40
41extern int readv( int fd, struct iovec* vecs, int count );
42extern int writev( int fd, const struct iovec* vecs, int count );
43
44#ifdef __cplusplus
45}
46#endif
47
48#endif
49
50#endif /* _LIBS_UTILS_UIO_H */
51
diff --git a/liblog/include/private/android_logger.h b/liblog/include/private/android_logger.h
new file mode 100644
index 000000000..9f81b1f06
--- /dev/null
+++ b/liblog/include/private/android_logger.h
@@ -0,0 +1,194 @@
1/*
2 * Copyright (C) 2015 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/* This file is used to define the internal protocol for the Android Logger */
18
19#ifndef _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
20#define _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_
21
22/* Android private interfaces */
23
24#include <stdbool.h>
25#include <stdint.h>
26#include <sys/types.h>
27
28#if (defined(__cplusplus) && defined(_USING_LIBCXX))
29extern "C++" {
30#include <string>
31}
32#endif
33
34#include <log/log_event_list.h>
35#include <log/log.h>
36
37#define LOGGER_MAGIC 'l'
38
39#if defined(__cplusplus)
40extern "C" {
41#endif
42
43/* Header Structure to pstore */
44typedef struct __attribute__((__packed__)) {
45 uint8_t magic;
46 uint16_t len;
47 uint16_t uid;
48 uint16_t pid;
49} android_pmsg_log_header_t;
50
51/* Header Structure to logd, and second header for pstore */
52typedef struct __attribute__((__packed__)) {
53 typeof_log_id_t id;
54 uint16_t tid;
55 log_time realtime;
56} android_log_header_t;
57
58/* Event Header Structure to logd */
59typedef struct __attribute__((__packed__)) {
60 int32_t tag; // Little Endian Order
61} android_event_header_t;
62
63/* Event payload EVENT_TYPE_INT */
64typedef struct __attribute__((__packed__)) {
65 int8_t type; // EVENT_TYPE_INT
66 int32_t data; // Little Endian Order
67} android_event_int_t;
68
69/* Event with single EVENT_TYPE_INT */
70typedef struct __attribute__((__packed__)) {
71 android_event_header_t header;
72 android_event_int_t payload;
73} android_log_event_int_t;
74
75/* Event payload EVENT_TYPE_LONG */
76typedef struct __attribute__((__packed__)) {
77 int8_t type; // EVENT_TYPE_LONG
78 int64_t data; // Little Endian Order
79} android_event_long_t;
80
81/* Event with single EVENT_TYPE_LONG */
82typedef struct __attribute__((__packed__)) {
83 android_event_header_t header;
84 android_event_long_t payload;
85} android_log_event_long_t;
86
87/*
88 * Event payload EVENT_TYPE_STRING
89 *
90 * Danger: do not embed this structure into another structure.
91 * This structure uses a flexible array member, and when
92 * compiled using g++, __builtin_object_size(data, 1) returns
93 * a bad value. This is possibly a g++ bug, or a bug due to
94 * the fact that flexible array members are not supported
95 * in C++.
96 * http://stackoverflow.com/questions/4412749/are-flexible-array-members-valid-in-c
97 */
98
99typedef struct __attribute__((__packed__)) {
100 int8_t type; // EVENT_TYPE_STRING;
101 int32_t length; // Little Endian Order
102 char data[];
103} android_event_string_t;
104
105/* Event with single EVENT_TYPE_STRING */
106typedef struct __attribute__((__packed__)) {
107 android_event_header_t header;
108 int8_t type; // EVENT_TYPE_STRING;
109 int32_t length; // Little Endian Order
110 char data[];
111} android_log_event_string_t;
112
113#define ANDROID_LOG_PMSG_FILE_MAX_SEQUENCE 256 /* 1MB file */
114#define ANDROID_LOG_PMSG_FILE_SEQUENCE 1000
115
116ssize_t __android_log_pmsg_file_write(
117 log_id_t logId,
118 char prio,
119 const char* filename,
120 const char* buf, size_t len);
121
122#define LOG_ID_ANY ((log_id_t)-1)
123#define ANDROID_LOG_ANY ANDROID_LOG_UNKNOWN
124
125/* first 5 arguments match __android_log_msg_file_write, a cast is safe */
126typedef ssize_t (*__android_log_pmsg_file_read_fn)(
127 log_id_t logId,
128 char prio,
129 const char* filename,
130 const char* buf, size_t len, void* arg);
131
132ssize_t __android_log_pmsg_file_read(
133 log_id_t logId, char prio, const char* prefix,
134 __android_log_pmsg_file_read_fn fn, void* arg);
135
136int __android_log_security_bwrite(int32_t tag, const void* payload, size_t len);
137int __android_log_security_bswrite(int32_t tag, const char* payload);
138int __android_log_security(); /* Device Owner is present */
139
140int __android_log_is_debuggable();
141
142#define BOOL_DEFAULT_FLAG_TRUE_FALSE 0x1
143#define BOOL_DEFAULT_FALSE 0x0 /* false if property not present */
144#define BOOL_DEFAULT_TRUE 0x1 /* true if property not present */
145#define BOOL_DEFAULT_FLAG_PERSIST 0x2 /* <key>, persist.<key>, ro.<key> */
146#define BOOL_DEFAULT_FLAG_ENG 0x4 /* off for user */
147#define BOOL_DEFAULT_FLAG_SVELTE 0x8 /* off for low_ram */
148bool __android_logger_property_get_bool(const char* key, int flag);
149
150#define LOG_BUFFER_SIZE (256 * 1024) /* Tuned with ro.logd.size per-platform */
151#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
152#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
153unsigned long __android_logger_get_buffer_size(log_id_t logId);
154bool __android_logger_valid_buffer_size(unsigned long value);
155
156/* Retrieve the composed event buffer */
157int android_log_write_list_buffer(android_log_context ctx, const char** msg);
158
159#ifdef __cplusplus
160#ifdef __class_android_log_event_list_defined
161#ifndef __class_android_log_event_list_private_defined
162#define __class_android_log_event_list_private_defined
163/* android_log_context C++ helpers */
164extern "C++" {
165class __android_log_event_list : public android_log_event_list {
166 __android_log_event_list(const android_log_event_list&) = delete;
167 void operator =(const __android_log_event_list&) = delete;
168
169public:
170 explicit __android_log_event_list(int tag) : android_log_event_list(tag) { }
171 explicit __android_log_event_list(log_msg& log_msg) : android_log_event_list(log_msg) { }
172
173#if defined(_USING_LIBCXX)
174 operator std::string() {
175 if (ret) return std::string("");
176 const char* cp = NULL;
177 ssize_t len = android_log_write_list_buffer(ctx, &cp);
178 if (len < 0) ret = len;
179 if (!cp || (len <= 0)) return std::string("");
180 return std::string(cp, len);
181 }
182#endif
183
184};
185}
186#endif
187#endif
188#endif
189
190#if defined(__cplusplus)
191}
192#endif
193
194#endif /* _SYSTEM_CORE_INCLUDE_PRIVATE_ANDROID_LOGGER_H_ */
diff --git a/liblog/include_vndk/android b/liblog/include_vndk/android
new file mode 120000
index 000000000..69fbc0947
--- /dev/null
+++ b/liblog/include_vndk/android
@@ -0,0 +1 @@
../../include/android/ \ No newline at end of file
diff --git a/liblog/include_vndk/log/log.h b/liblog/include_vndk/log/log.h
new file mode 100644
index 000000000..f3eb3fe14
--- /dev/null
+++ b/liblog/include_vndk/log/log.h
@@ -0,0 +1,22 @@
1/*Special log.h file for VNDK linking modules*/
2
3#ifndef _LIBS_LOG_LOG_H
4#define _LIBS_LOG_LOG_H
5
6#include <android/log.h>
7
8/*The following files will be included once they are available*/
9/*#include <log/log_id.h>*/
10/*#include <log/log_radio.h>*/
11
12/*
13 * LOG_TAG is the local tag used for the following simplified
14 * logging macros. You can change this preprocessor definition
15 * before using the other macros to change the tag.
16 */
17
18#ifndef LOG_TAG
19#define LOG_TAG NULL
20#endif
21
22#endif /*_LIBS_LOG_LOG_H*/