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