1 /*
2  * Copyright 2013 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 #pragma once
18 
19 #include <android/log.h>
20 
21 #ifndef LOG_NDEBUG
22 #ifdef NDEBUG
23 #define LOG_NDEBUG 1
24 #else
25 #define LOG_NDEBUG 0
26 #endif
27 #endif
28 
29 
30 /*
31  * Basic log message macros intended to emulate the behavior of log/log.h
32  * in system core.  This should be dependent only on ndk exposed logging
33  * functionality.
34  */
35 
36 #ifndef ALOG
37 #define ALOG(priority, tag, fmt, ...) \
38     __android_log_print(ANDROID_##priority, tag, fmt, __VA_ARGS__)
39 #endif
40 
41 #ifndef ALOGV
42 #if LOG_NDEBUG
43 #define ALOGV(...)   ((void)0)
44 #else
45 #define ALOGV(...) ((void)ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
46 #endif
47 #endif
48 
49 #ifndef ALOGD
50 #define ALOGD(...) ((void)ALOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__))
51 #endif
52 
53 #ifndef ALOGI
54 #define ALOGI(...) ((void)ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__))
55 #endif
56 
57 #ifndef ALOGW
58 #define ALOGW(...) ((void)ALOG(LOG_WARN, LOG_TAG, __VA_ARGS__))
59 #endif
60 
61 #ifndef ALOGE
62 #define ALOGE(...) ((void)ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__))
63 #endif
64 
65 #ifndef ALOGF
66 #define ALOGF(...) ((void)ALOG(LOG_FATAL, LOG_TAG, __VA_ARGS__))
67 #endif
68 
69 /*
70  * Log a fatal error if cond is true. The condition test is inverted from
71  * assert(3) semantics. The test and message are not stripped from release
72  * builds
73  */
74 #ifndef ALOG_ALWAYS_FATAL_IF
75 #define ALOG_ALWAYS_FATAL_IF(cond, ...) \
76     if (cond) __android_log_assert(#cond, LOG_TAG, __VA_ARGS__)
77 #endif
78 
79