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_SYSTEM_H 18 #define _LIBS_LOG_LOG_SYSTEM_H 19 20 #include <android/log.h> 21 #include <log/log_id.h> 22 23 /* 24 * Normally we strip the effects of ALOGV (VERBOSE messages), 25 * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the 26 * release builds be defining NDEBUG. You can modify this (for 27 * example with "#define LOG_NDEBUG 0" at the top of your source 28 * file) to change that behavior. 29 */ 30 31 #ifndef LOG_NDEBUG 32 #ifdef NDEBUG 33 #define LOG_NDEBUG 1 34 #else 35 #define LOG_NDEBUG 0 36 #endif 37 #endif 38 39 #ifndef __predict_false 40 #define __predict_false(exp) __builtin_expect((exp) != 0, 0) 41 #endif 42 43 /* 44 * Simplified macro to send a verbose system log message using current LOG_TAG. 45 */ 46 #ifndef SLOGV 47 #define __SLOGV(...) \ 48 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, \ 49 __VA_ARGS__)) 50 #if LOG_NDEBUG 51 #define SLOGV(...) \ 52 do { \ 53 if (0) { \ 54 __SLOGV(__VA_ARGS__); \ 55 } \ 56 } while (0) 57 #else 58 #define SLOGV(...) __SLOGV(__VA_ARGS__) 59 #endif 60 #endif 61 62 #ifndef SLOGV_IF 63 #if LOG_NDEBUG 64 #define SLOGV_IF(cond, ...) ((void)0) 65 #else 66 #define SLOGV_IF(cond, ...) \ 67 ((__predict_false(cond)) \ 68 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, \ 69 LOG_TAG, __VA_ARGS__)) \ 70 : (void)0) 71 #endif 72 #endif 73 74 /* 75 * Simplified macro to send a debug system log message using current LOG_TAG. 76 */ 77 #ifndef SLOGD 78 #define SLOGD(...) \ 79 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, \ 80 __VA_ARGS__)) 81 #endif 82 83 #ifndef SLOGD_IF 84 #define SLOGD_IF(cond, ...) \ 85 ((__predict_false(cond)) \ 86 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, \ 87 LOG_TAG, __VA_ARGS__)) \ 88 : (void)0) 89 #endif 90 91 /* 92 * Simplified macro to send an info system log message using current LOG_TAG. 93 */ 94 #ifndef SLOGI 95 #define SLOGI(...) \ 96 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, \ 97 __VA_ARGS__)) 98 #endif 99 100 #ifndef SLOGI_IF 101 #define SLOGI_IF(cond, ...) \ 102 ((__predict_false(cond)) \ 103 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, \ 104 LOG_TAG, __VA_ARGS__)) \ 105 : (void)0) 106 #endif 107 108 /* 109 * Simplified macro to send a warning system log message using current LOG_TAG. 110 */ 111 #ifndef SLOGW 112 #define SLOGW(...) \ 113 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, \ 114 __VA_ARGS__)) 115 #endif 116 117 #ifndef SLOGW_IF 118 #define SLOGW_IF(cond, ...) \ 119 ((__predict_false(cond)) \ 120 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, \ 121 LOG_TAG, __VA_ARGS__)) \ 122 : (void)0) 123 #endif 124 125 /* 126 * Simplified macro to send an error system log message using current LOG_TAG. 127 */ 128 #ifndef SLOGE 129 #define SLOGE(...) \ 130 ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, \ 131 __VA_ARGS__)) 132 #endif 133 134 #ifndef SLOGE_IF 135 #define SLOGE_IF(cond, ...) \ 136 ((__predict_false(cond)) \ 137 ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, \ 138 LOG_TAG, __VA_ARGS__)) \ 139 : (void)0) 140 #endif 141 142 #endif /* _LIBS_LOG_LOG_SYSTEM_H */ 143