rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
| 18 | #ifndef TEL_DEMO_SRC_UTIL_LOG_EXTRA_H_ |
| 19 | #define TEL_DEMO_SRC_UTIL_LOG_EXTRA_H_ |
| 20 | |
| 21 | /***************************************************************************** |
| 22 | * Include |
| 23 | *****************************************************************************/ |
| 24 | |
| 25 | #include <log/log.h> |
| 26 | |
| 27 | /***************************************************************************** |
| 28 | * Example |
| 29 | *****************************************************************************/ |
| 30 | /* Add a debug log with your tag, write it like: |
| 31 | * LOG_D(tag, "this is a sample"); |
| 32 | * |
| 33 | * Print a variable, write it like: |
| 34 | * LOG_D(tag, "this is a sample %d", variable); |
| 35 | * |
| 36 | * Print multi-variable, write it like: |
| 37 | * LOG_D(tag, "this is a sample %d,%d", variable1, variable2); |
| 38 | * |
| 39 | * Staple output format |
| 40 | * %c char |
| 41 | * %s char* string |
| 42 | * %d sign decimal |
| 43 | * %p pointer |
| 44 | * %x hex |
| 45 | * |
| 46 | * Add a debug log with your condition and tag, write it like: |
| 47 | * LOG_D_IF(condition, tag, "this is a sample"); |
| 48 | * When condition is not 0 (this is true), the log will be printed, otherwise, no log printed. |
| 49 | * |
| 50 | */ |
| 51 | |
| 52 | /***************************************************************************** |
| 53 | * Define |
| 54 | *****************************************************************************/ |
| 55 | |
| 56 | /* |
| 57 | * Simplified macro to send a verbose radio log message using the user given tag - _tag. |
| 58 | */ |
| 59 | #ifndef LOG_V |
| 60 | #define __LOG_V(_tag, ...) \ |
| 61 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, _tag, __VA_ARGS__)) |
| 62 | #if LOG_NDEBUG |
| 63 | #define LOG_V(_tag, ...) do { if (0) { __LOG_V(_tag, __VA_ARGS__); } } while (0) |
| 64 | #else |
| 65 | #define LOG_V(_tag, ...) __LOG_V(_tag, __VA_ARGS__) |
| 66 | #endif |
| 67 | #endif |
| 68 | |
| 69 | #define CONDITION(cond) (__builtin_expect((cond) != 0, 0)) |
| 70 | |
| 71 | #ifndef LOG_V_IF |
| 72 | #if LOG_NDEBUG |
| 73 | #define LOG_V_IF(cond, _tag, ...) ((void)0) |
| 74 | #else |
| 75 | #define LOG_V_IF(cond, _tag, ...) \ |
| 76 | ( (CONDITION(cond)) \ |
| 77 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, _tag, __VA_ARGS__)) \ |
| 78 | : (void)0 ) |
| 79 | #endif |
| 80 | #endif |
| 81 | |
| 82 | /* |
| 83 | * Simplified macro to send a debug radio log message using the user given tag - _tag. |
| 84 | */ |
| 85 | #ifndef LOG_D |
| 86 | #define LOG_D(_tag, ...) \ |
| 87 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, _tag, __VA_ARGS__)) |
| 88 | #endif |
| 89 | |
| 90 | #ifndef LOG_D_IF |
| 91 | #define LOG_D_IF(cond, _tag, ...) \ |
| 92 | ( (CONDITION(cond)) \ |
| 93 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, _tag, __VA_ARGS__)) \ |
| 94 | : (void)0 ) |
| 95 | #endif |
| 96 | |
| 97 | /* |
| 98 | * Simplified macro to send an info radio log message using the user given tag - _tag. |
| 99 | */ |
| 100 | #ifndef LOG_I |
| 101 | #define LOG_I(_tag, ...) \ |
| 102 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, _tag, __VA_ARGS__)) |
| 103 | #endif |
| 104 | |
| 105 | #ifndef LOG_I_IF |
| 106 | #define LOG_I_IF(cond, _tag, ...) \ |
| 107 | ( (CONDITION(cond)) \ |
| 108 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, _tag, __VA_ARGS__)) \ |
| 109 | : (void)0 ) |
| 110 | #endif |
| 111 | |
| 112 | /* |
| 113 | * Simplified macro to send a warning radio log message using the user given tag - _tag. |
| 114 | */ |
| 115 | #ifndef LOG_W |
| 116 | #define LOG_W(_tag, ...) \ |
| 117 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, _tag, __VA_ARGS__)) |
| 118 | #endif |
| 119 | |
| 120 | #ifndef LOG_W_IF |
| 121 | #define LOG_W_IF(cond, _tag, ...) \ |
| 122 | ( (CONDITION(cond)) \ |
| 123 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, _tag, __VA_ARGS__)) \ |
| 124 | : (void)0 ) |
| 125 | #endif |
| 126 | |
| 127 | /* |
| 128 | * Simplified macro to send an error radio log message using the user given tag - _tag. |
| 129 | */ |
| 130 | #ifndef LOG_E |
| 131 | #define LOG_E(_tag, ...) \ |
| 132 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, _tag, __VA_ARGS__)) |
| 133 | #endif |
| 134 | |
| 135 | #ifndef LOG_E_IF |
| 136 | #define LOG_E_IF(cond, _tag, ...) \ |
| 137 | ( (CONDITION(cond)) \ |
| 138 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, _tag, __VA_ARGS__)) \ |
| 139 | : (void)0 ) |
| 140 | #endif |
| 141 | |
| 142 | #ifndef ASSERT_EX |
| 143 | #define ASSERT_EX(_expr) \ |
| 144 | do { \ |
| 145 | if (!(_expr)) { \ |
| 146 | LOG_E("ASSERT_EX", "ASSERT_EX:%s, %d", __FILE__, __LINE__); \ |
| 147 | LOG_ALWAYS_FATAL(); \ |
| 148 | } \ |
| 149 | } while(0) |
| 150 | #endif |
| 151 | |
| 152 | |
| 153 | |
| 154 | #endif /* TEL_DEMO_SRC_UTIL_LOG_EXTRA_H_ */ |