diff options
author | Mark Salyzyn | 2017-01-09 14:44:13 -0600 |
---|---|---|
committer | Mark Salyzyn | 2017-01-25 17:41:43 -0600 |
commit | 5c967da341c9395a4c378c149f326505224ec66e (patch) | |
tree | 0e1de2d192d55de6300d99269441882ccbb0b2bd /liblog/include | |
parent | 01678a0c84e1f94420630709fe7aea7b4357f019 (diff) | |
download | platform-system-core-5c967da341c9395a4c378c149f326505224ec66e.tar.gz platform-system-core-5c967da341c9395a4c378c149f326505224ec66e.tar.xz platform-system-core-5c967da341c9395a4c378c149f326505224ec66e.zip |
ndk: reverse course on android/log.h
move LOG macros to log/log_main.h
move include/android/log.h to liblog/include/android/log.h
Test: compile of all components and gTest liblog-unit-tests
Bug: 34250038
Bug: 30465923
Change-Id: If182dd9b83689e8b7bc1a44b2f5d913c7ee5eeee
Diffstat (limited to 'liblog/include')
-rw-r--r-- | liblog/include/android/log.h | 156 | ||||
-rw-r--r-- | liblog/include/log/log.h | 17 | ||||
-rw-r--r-- | liblog/include/log/log_main.h | 395 |
3 files changed, 568 insertions, 0 deletions
diff --git a/liblog/include/android/log.h b/liblog/include/android/log.h new file mode 100644 index 000000000..9f198fe87 --- /dev/null +++ b/liblog/include/android/log.h | |||
@@ -0,0 +1,156 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2009 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef _ANDROID_LOG_H | ||
18 | #define _ANDROID_LOG_H | ||
19 | |||
20 | /****************************************************************** | ||
21 | * | ||
22 | * IMPORTANT NOTICE: | ||
23 | * | ||
24 | * This file is part of Android's set of stable system headers | ||
25 | * exposed by the Android NDK (Native Development Kit) since | ||
26 | * platform release 1.5 | ||
27 | * | ||
28 | * Third-party source AND binary code relies on the definitions | ||
29 | * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. | ||
30 | * | ||
31 | * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) | ||
32 | * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS | ||
33 | * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY | ||
34 | * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES | ||
35 | */ | ||
36 | |||
37 | /* | ||
38 | * Support routines to send messages to the Android in-kernel log buffer, | ||
39 | * which can later be accessed through the 'logcat' utility. | ||
40 | * | ||
41 | * Each log message must have | ||
42 | * - a priority | ||
43 | * - a log tag | ||
44 | * - some text | ||
45 | * | ||
46 | * The tag normally corresponds to the component that emits the log message, | ||
47 | * and should be reasonably small. | ||
48 | * | ||
49 | * Log message text may be truncated to less than an implementation-specific | ||
50 | * limit (e.g. 1023 characters max). | ||
51 | * | ||
52 | * Note that a newline character ("\n") will be appended automatically to your | ||
53 | * log message, if not already there. It is not possible to send several messages | ||
54 | * and have them appear on a single line in logcat. | ||
55 | * | ||
56 | * PLEASE USE LOGS WITH MODERATION: | ||
57 | * | ||
58 | * - Sending log messages eats CPU and slow down your application and the | ||
59 | * system. | ||
60 | * | ||
61 | * - The circular log buffer is pretty small (<64KB), sending many messages | ||
62 | * might push off other important log messages from the rest of the system. | ||
63 | * | ||
64 | * - In release builds, only send log messages to account for exceptional | ||
65 | * conditions. | ||
66 | * | ||
67 | * NOTE: These functions MUST be implemented by /system/lib/liblog.so | ||
68 | */ | ||
69 | |||
70 | #include <stdarg.h> | ||
71 | |||
72 | #ifdef __cplusplus | ||
73 | extern "C" { | ||
74 | #endif | ||
75 | |||
76 | /* | ||
77 | * Android log priority values, in ascending priority order. | ||
78 | */ | ||
79 | typedef enum android_LogPriority { | ||
80 | ANDROID_LOG_UNKNOWN = 0, | ||
81 | ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */ | ||
82 | ANDROID_LOG_VERBOSE, | ||
83 | ANDROID_LOG_DEBUG, | ||
84 | ANDROID_LOG_INFO, | ||
85 | ANDROID_LOG_WARN, | ||
86 | ANDROID_LOG_ERROR, | ||
87 | ANDROID_LOG_FATAL, | ||
88 | ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */ | ||
89 | } android_LogPriority; | ||
90 | |||
91 | /* | ||
92 | * Send a simple string to the log. | ||
93 | */ | ||
94 | int __android_log_write(int prio, const char* tag, const char* text); | ||
95 | |||
96 | /* | ||
97 | * Send a formatted string to the log, used like printf(fmt,...) | ||
98 | */ | ||
99 | int __android_log_print(int prio, const char* tag, const char* fmt, ...) | ||
100 | #if defined(__GNUC__) | ||
101 | #ifdef __USE_MINGW_ANSI_STDIO | ||
102 | #if __USE_MINGW_ANSI_STDIO | ||
103 | __attribute__ ((__format__(gnu_printf, 3, 4))) | ||
104 | #else | ||
105 | __attribute__ ((__format__(printf, 3, 4))) | ||
106 | #endif | ||
107 | #else | ||
108 | __attribute__ ((__format__(printf, 3, 4))) | ||
109 | #endif | ||
110 | #endif | ||
111 | ; | ||
112 | |||
113 | /* | ||
114 | * A variant of __android_log_print() that takes a va_list to list | ||
115 | * additional parameters. | ||
116 | */ | ||
117 | int __android_log_vprint(int prio, const char* tag, | ||
118 | const char* fmt, va_list ap) | ||
119 | #if defined(__GNUC__) | ||
120 | #ifdef __USE_MINGW_ANSI_STDIO | ||
121 | #if __USE_MINGW_ANSI_STDIO | ||
122 | __attribute__ ((__format__(gnu_printf, 3, 0))) | ||
123 | #else | ||
124 | __attribute__ ((__format__(printf, 3, 0))) | ||
125 | #endif | ||
126 | #else | ||
127 | __attribute__ ((__format__(printf, 3, 0))) | ||
128 | #endif | ||
129 | #endif | ||
130 | ; | ||
131 | |||
132 | /* | ||
133 | * Log an assertion failure and abort the process to have a chance | ||
134 | * to inspect it if a debugger is attached. This uses the FATAL priority. | ||
135 | */ | ||
136 | void __android_log_assert(const char* cond, const char* tag, | ||
137 | const char* fmt, ...) | ||
138 | #if defined(__GNUC__) | ||
139 | __attribute__ ((__noreturn__)) | ||
140 | #ifdef __USE_MINGW_ANSI_STDIO | ||
141 | #if __USE_MINGW_ANSI_STDIO | ||
142 | __attribute__ ((__format__(gnu_printf, 3, 4))) | ||
143 | #else | ||
144 | __attribute__ ((__format__(printf, 3, 4))) | ||
145 | #endif | ||
146 | #else | ||
147 | __attribute__ ((__format__(printf, 3, 4))) | ||
148 | #endif | ||
149 | #endif | ||
150 | ; | ||
151 | |||
152 | #ifdef __cplusplus | ||
153 | } | ||
154 | #endif | ||
155 | |||
156 | #endif /* _ANDROID_LOG_H */ | ||
diff --git a/liblog/include/log/log.h b/liblog/include/log/log.h index ece9ea6d1..37d30bc73 100644 --- a/liblog/include/log/log.h +++ b/liblog/include/log/log.h | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | 29 | ||
30 | #include <android/log.h> | 30 | #include <android/log.h> |
31 | #include <log/log_main.h> | ||
31 | #include <log/uio.h> /* helper to define iovec for portability */ | 32 | #include <log/uio.h> /* helper to define iovec for portability */ |
32 | 33 | ||
33 | #ifdef __cplusplus | 34 | #ifdef __cplusplus |
@@ -44,6 +45,22 @@ extern "C" { | |||
44 | #define LOG_TAG NULL | 45 | #define LOG_TAG NULL |
45 | #endif | 46 | #endif |
46 | 47 | ||
48 | /* | ||
49 | * Normally we strip the effects of ALOGV (VERBOSE messages), | ||
50 | * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the | ||
51 | * release builds be defining NDEBUG. You can modify this (for | ||
52 | * example with "#define LOG_NDEBUG 0" at the top of your source | ||
53 | * file) to change that behavior. | ||
54 | */ | ||
55 | |||
56 | #ifndef LOG_NDEBUG | ||
57 | #ifdef NDEBUG | ||
58 | #define LOG_NDEBUG 1 | ||
59 | #else | ||
60 | #define LOG_NDEBUG 0 | ||
61 | #endif | ||
62 | #endif | ||
63 | |||
47 | /* --------------------------------------------------------------------- */ | 64 | /* --------------------------------------------------------------------- */ |
48 | 65 | ||
49 | /* | 66 | /* |
diff --git a/liblog/include/log/log_main.h b/liblog/include/log/log_main.h new file mode 100644 index 000000000..f45397ab8 --- /dev/null +++ b/liblog/include/log/log_main.h | |||
@@ -0,0 +1,395 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005-2017 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_MAIN_H | ||
18 | #define _LIBS_LOG_LOG_MAIN_H | ||
19 | |||
20 | #include <android/log.h> | ||
21 | |||
22 | #ifdef __cplusplus | ||
23 | extern "C" { | ||
24 | #endif | ||
25 | |||
26 | /* | ||
27 | * Normally we strip the effects of ALOGV (VERBOSE messages), | ||
28 | * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the | ||
29 | * release builds be defining NDEBUG. You can modify this (for | ||
30 | * example with "#define LOG_NDEBUG 0" at the top of your source | ||
31 | * file) to change that behavior. | ||
32 | */ | ||
33 | |||
34 | #ifndef LOG_NDEBUG | ||
35 | #ifdef NDEBUG | ||
36 | #define LOG_NDEBUG 1 | ||
37 | #else | ||
38 | #define LOG_NDEBUG 0 | ||
39 | #endif | ||
40 | #endif | ||
41 | |||
42 | /* --------------------------------------------------------------------- */ | ||
43 | |||
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 | */ | ||
50 | #if defined(__clang__) | ||
51 | #pragma clang diagnostic push | ||
52 | #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" | ||
53 | #endif | ||
54 | |||
55 | #ifndef __predict_false | ||
56 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) | ||
57 | #endif | ||
58 | |||
59 | #define android_writeLog(prio, tag, text) \ | ||
60 | __android_log_write(prio, tag, text) | ||
61 | |||
62 | #define android_printLog(prio, tag, ...) \ | ||
63 | __android_log_print(prio, tag, __VA_ARGS__) | ||
64 | |||
65 | #define android_vprintLog(prio, cond, tag, ...) \ | ||
66 | __android_log_vprint(prio, tag, __VA_ARGS__) | ||
67 | |||
68 | /* | ||
69 | * Log macro that allows you to specify a number for the priority. | ||
70 | */ | ||
71 | #ifndef LOG_PRI | ||
72 | #define LOG_PRI(priority, tag, ...) \ | ||
73 | android_printLog(priority, tag, __VA_ARGS__) | ||
74 | #endif | ||
75 | |||
76 | /* | ||
77 | * Log macro that allows you to pass in a varargs ("args" is a va_list). | ||
78 | */ | ||
79 | #ifndef LOG_PRI_VA | ||
80 | #define LOG_PRI_VA(priority, tag, fmt, args) \ | ||
81 | android_vprintLog(priority, NULL, tag, fmt, args) | ||
82 | #endif | ||
83 | |||
84 | /* --------------------------------------------------------------------- */ | ||
85 | |||
86 | /* XXX Macros to work around syntax errors in places where format string | ||
87 | * arg is not passed to ALOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF | ||
88 | * (happens only in debug builds). | ||
89 | */ | ||
90 | |||
91 | /* Returns 2nd arg. Used to substitute default value if caller's vararg list | ||
92 | * is empty. | ||
93 | */ | ||
94 | #define __android_second(dummy, second, ...) second | ||
95 | |||
96 | /* If passed multiple args, returns ',' followed by all but 1st arg, otherwise | ||
97 | * returns nothing. | ||
98 | */ | ||
99 | #define __android_rest(first, ...) , ## __VA_ARGS__ | ||
100 | |||
101 | #define android_printAssert(cond, tag, ...) \ | ||
102 | __android_log_assert(cond, tag, \ | ||
103 | __android_second(0, ## __VA_ARGS__, NULL) __android_rest(__VA_ARGS__)) | ||
104 | |||
105 | /* | ||
106 | * Log a fatal error. If the given condition fails, this stops program | ||
107 | * execution like a normal assertion, but also generating the given message. | ||
108 | * It is NOT stripped from release builds. Note that the condition test | ||
109 | * is -inverted- from the normal assert() semantics. | ||
110 | */ | ||
111 | #ifndef LOG_ALWAYS_FATAL_IF | ||
112 | #define LOG_ALWAYS_FATAL_IF(cond, ...) \ | ||
113 | ( (__predict_false(cond)) \ | ||
114 | ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \ | ||
115 | : (void)0 ) | ||
116 | #endif | ||
117 | |||
118 | #ifndef LOG_ALWAYS_FATAL | ||
119 | #define LOG_ALWAYS_FATAL(...) \ | ||
120 | ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) ) | ||
121 | #endif | ||
122 | |||
123 | /* | ||
124 | * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that | ||
125 | * are stripped out of release builds. | ||
126 | */ | ||
127 | |||
128 | #if LOG_NDEBUG | ||
129 | |||
130 | #ifndef LOG_FATAL_IF | ||
131 | #define LOG_FATAL_IF(cond, ...) ((void)0) | ||
132 | #endif | ||
133 | #ifndef LOG_FATAL | ||
134 | #define LOG_FATAL(...) ((void)0) | ||
135 | #endif | ||
136 | |||
137 | #else | ||
138 | |||
139 | #ifndef LOG_FATAL_IF | ||
140 | #define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__) | ||
141 | #endif | ||
142 | #ifndef LOG_FATAL | ||
143 | #define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__) | ||
144 | #endif | ||
145 | |||
146 | #endif | ||
147 | |||
148 | /* | ||
149 | * Assertion that generates a log message when the assertion fails. | ||
150 | * Stripped out of release builds. Uses the current LOG_TAG. | ||
151 | */ | ||
152 | #ifndef ALOG_ASSERT | ||
153 | #define ALOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__) | ||
154 | #endif | ||
155 | |||
156 | /* --------------------------------------------------------------------- */ | ||
157 | |||
158 | /* | ||
159 | * C/C++ logging functions. See the logging documentation for API details. | ||
160 | * | ||
161 | * We'd like these to be available from C code (in case we import some from | ||
162 | * somewhere), so this has a C interface. | ||
163 | * | ||
164 | * The output will be correct when the log file is shared between multiple | ||
165 | * threads and/or multiple processes so long as the operating system | ||
166 | * supports O_APPEND. These calls have mutex-protected data structures | ||
167 | * and so are NOT reentrant. Do not use LOG in a signal handler. | ||
168 | */ | ||
169 | |||
170 | /* --------------------------------------------------------------------- */ | ||
171 | |||
172 | /* | ||
173 | * Simplified macro to send a verbose log message using the current LOG_TAG. | ||
174 | */ | ||
175 | #ifndef ALOGV | ||
176 | #define __ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) | ||
177 | #if LOG_NDEBUG | ||
178 | #define ALOGV(...) do { if (0) { __ALOGV(__VA_ARGS__); } } while (0) | ||
179 | #else | ||
180 | #define ALOGV(...) __ALOGV(__VA_ARGS__) | ||
181 | #endif | ||
182 | #endif | ||
183 | |||
184 | #ifndef ALOGV_IF | ||
185 | #if LOG_NDEBUG | ||
186 | #define ALOGV_IF(cond, ...) ((void)0) | ||
187 | #else | ||
188 | #define ALOGV_IF(cond, ...) \ | ||
189 | ( (__predict_false(cond)) \ | ||
190 | ? ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ | ||
191 | : (void)0 ) | ||
192 | #endif | ||
193 | #endif | ||
194 | |||
195 | /* | ||
196 | * Simplified macro to send a debug log message using the current LOG_TAG. | ||
197 | */ | ||
198 | #ifndef ALOGD | ||
199 | #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) | ||
200 | #endif | ||
201 | |||
202 | #ifndef ALOGD_IF | ||
203 | #define ALOGD_IF(cond, ...) \ | ||
204 | ( (__predict_false(cond)) \ | ||
205 | ? ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ | ||
206 | : (void)0 ) | ||
207 | #endif | ||
208 | |||
209 | /* | ||
210 | * Simplified macro to send an info log message using the current LOG_TAG. | ||
211 | */ | ||
212 | #ifndef ALOGI | ||
213 | #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) | ||
214 | #endif | ||
215 | |||
216 | #ifndef ALOGI_IF | ||
217 | #define ALOGI_IF(cond, ...) \ | ||
218 | ( (__predict_false(cond)) \ | ||
219 | ? ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ | ||
220 | : (void)0 ) | ||
221 | #endif | ||
222 | |||
223 | /* | ||
224 | * Simplified macro to send a warning log message using the current LOG_TAG. | ||
225 | */ | ||
226 | #ifndef ALOGW | ||
227 | #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) | ||
228 | #endif | ||
229 | |||
230 | #ifndef ALOGW_IF | ||
231 | #define ALOGW_IF(cond, ...) \ | ||
232 | ( (__predict_false(cond)) \ | ||
233 | ? ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ | ||
234 | : (void)0 ) | ||
235 | #endif | ||
236 | |||
237 | /* | ||
238 | * Simplified macro to send an error log message using the current LOG_TAG. | ||
239 | */ | ||
240 | #ifndef ALOGE | ||
241 | #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) | ||
242 | #endif | ||
243 | |||
244 | #ifndef ALOGE_IF | ||
245 | #define ALOGE_IF(cond, ...) \ | ||
246 | ( (__predict_false(cond)) \ | ||
247 | ? ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ | ||
248 | : (void)0 ) | ||
249 | #endif | ||
250 | |||
251 | /* --------------------------------------------------------------------- */ | ||
252 | |||
253 | /* | ||
254 | * Conditional based on whether the current LOG_TAG is enabled at | ||
255 | * verbose priority. | ||
256 | */ | ||
257 | #ifndef IF_ALOGV | ||
258 | #if LOG_NDEBUG | ||
259 | #define IF_ALOGV() if (false) | ||
260 | #else | ||
261 | #define IF_ALOGV() IF_ALOG(LOG_VERBOSE, LOG_TAG) | ||
262 | #endif | ||
263 | #endif | ||
264 | |||
265 | /* | ||
266 | * Conditional based on whether the current LOG_TAG is enabled at | ||
267 | * debug priority. | ||
268 | */ | ||
269 | #ifndef IF_ALOGD | ||
270 | #define IF_ALOGD() IF_ALOG(LOG_DEBUG, LOG_TAG) | ||
271 | #endif | ||
272 | |||
273 | /* | ||
274 | * Conditional based on whether the current LOG_TAG is enabled at | ||
275 | * info priority. | ||
276 | */ | ||
277 | #ifndef IF_ALOGI | ||
278 | #define IF_ALOGI() IF_ALOG(LOG_INFO, LOG_TAG) | ||
279 | #endif | ||
280 | |||
281 | /* | ||
282 | * Conditional based on whether the current LOG_TAG is enabled at | ||
283 | * warn priority. | ||
284 | */ | ||
285 | #ifndef IF_ALOGW | ||
286 | #define IF_ALOGW() IF_ALOG(LOG_WARN, LOG_TAG) | ||
287 | #endif | ||
288 | |||
289 | /* | ||
290 | * Conditional based on whether the current LOG_TAG is enabled at | ||
291 | * error priority. | ||
292 | */ | ||
293 | #ifndef IF_ALOGE | ||
294 | #define IF_ALOGE() IF_ALOG(LOG_ERROR, LOG_TAG) | ||
295 | #endif | ||
296 | |||
297 | /* --------------------------------------------------------------------- */ | ||
298 | |||
299 | /* | ||
300 | * Basic log message macro. | ||
301 | * | ||
302 | * Example: | ||
303 | * ALOG(LOG_WARN, NULL, "Failed with error %d", errno); | ||
304 | * | ||
305 | * The second argument may be NULL or "" to indicate the "global" tag. | ||
306 | */ | ||
307 | #ifndef ALOG | ||
308 | #define ALOG(priority, tag, ...) \ | ||
309 | LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) | ||
310 | #endif | ||
311 | |||
312 | /* | ||
313 | * Conditional given a desired logging priority and tag. | ||
314 | */ | ||
315 | #ifndef IF_ALOG | ||
316 | #define IF_ALOG(priority, tag) \ | ||
317 | if (android_testLog(ANDROID_##priority, tag)) | ||
318 | #endif | ||
319 | |||
320 | /* --------------------------------------------------------------------- */ | ||
321 | |||
322 | /* | ||
323 | * IF_ALOG uses android_testLog, but IF_ALOG can be overridden. | ||
324 | * android_testLog will remain constant in its purpose as a wrapper | ||
325 | * for Android logging filter policy, and can be subject to | ||
326 | * change. It can be reused by the developers that override | ||
327 | * IF_ALOG as a convenient means to reimplement their policy | ||
328 | * over Android. | ||
329 | */ | ||
330 | |||
331 | #ifndef __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE | ||
332 | #ifndef __ANDROID_API__ | ||
333 | #define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 2 | ||
334 | #elif __ANDROID_API__ > 24 /* > Nougat */ | ||
335 | #define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 2 | ||
336 | #elif __ANDROID_API__ > 22 /* > Lollipop */ | ||
337 | #define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 1 | ||
338 | #else | ||
339 | #define __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE 0 | ||
340 | #endif | ||
341 | #endif | ||
342 | |||
343 | #if __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE | ||
344 | |||
345 | /* | ||
346 | * Use the per-tag properties "log.tag.<tagname>" to generate a runtime | ||
347 | * result of non-zero to expose a log. prio is ANDROID_LOG_VERBOSE to | ||
348 | * ANDROID_LOG_FATAL. default_prio if no property. Undefined behavior if | ||
349 | * any other value. | ||
350 | */ | ||
351 | int __android_log_is_loggable(int prio, const char* tag, int default_prio); | ||
352 | |||
353 | #if __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE > 1 | ||
354 | #include <sys/types.h> | ||
355 | |||
356 | int __android_log_is_loggable_len(int prio, const char* tag, size_t len, | ||
357 | int default_prio); | ||
358 | |||
359 | #if LOG_NDEBUG /* Production */ | ||
360 | #define android_testLog(prio, tag) \ | ||
361 | (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ | ||
362 | ANDROID_LOG_DEBUG) != 0) | ||
363 | #else | ||
364 | #define android_testLog(prio, tag) \ | ||
365 | (__android_log_is_loggable_len(prio, tag, (tag && *tag) ? strlen(tag) : 0, \ | ||
366 | ANDROID_LOG_VERBOSE) != 0) | ||
367 | #endif | ||
368 | |||
369 | #else | ||
370 | |||
371 | #if LOG_NDEBUG /* Production */ | ||
372 | #define android_testLog(prio, tag) \ | ||
373 | (__android_log_is_loggable(prio, tag, ANDROID_LOG_DEBUG) != 0) | ||
374 | #else | ||
375 | #define android_testLog(prio, tag) \ | ||
376 | (__android_log_is_loggable(prio, tag, ANDROID_LOG_VERBOSE) != 0) | ||
377 | #endif | ||
378 | |||
379 | #endif | ||
380 | |||
381 | #else /* __ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE */ | ||
382 | |||
383 | #define android_testLog(prio, tag) (1) | ||
384 | |||
385 | #endif /* !__ANDROID_USE_LIBLOG_LOGGABLE_INTERFACE */ | ||
386 | |||
387 | #if defined(__clang__) | ||
388 | #pragma clang diagnostic pop | ||
389 | #endif | ||
390 | |||
391 | #ifdef __cplusplus | ||
392 | } | ||
393 | #endif | ||
394 | |||
395 | #endif /* _LIBS_LOG_LOG_MAIN_H */ | ||