1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_AV_TRANSPORT_LOG_H 17 #define OHOS_AV_TRANSPORT_LOG_H 18 19 #include <cinttypes> 20 #include <inttypes.h> 21 #include <string> 22 23 #include "hilog/log.h" 24 25 namespace OHOS { 26 namespace DistributedHardware { 27 #undef LOG_TAG 28 #define LOG_TAG "DAVTRANS" 29 30 #define AVTRANS_LOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, \ 31 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 32 33 #define AVTRANS_LOGI(fmt, ...) HILOG_INFO(LOG_CORE, \ 34 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 35 36 #define AVTRANS_LOGW(fmt, ...) HILOG_WARN(LOG_CORE, \ 37 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 38 39 #define AVTRANS_LOGE(fmt, ...) HILOG_ERROR(LOG_CORE, \ 40 "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__) 41 42 std::string GetAnonyString(const std::string &value); 43 std::string GetAnonyInt32(const int32_t value); 44 45 #ifndef TRUE_RETURN 46 #define TRUE_RETURN(exec, fmt, args...) \ 47 do { \ 48 bool retCode = (exec); \ 49 if (retCode) { \ 50 AVTRANS_LOGE(fmt, ##args); \ 51 return; \ 52 } \ 53 } while (0) 54 #endif 55 56 #ifndef TRUE_RETURN_V 57 #define TRUE_RETURN_V(exec, ret) \ 58 do { \ 59 bool retCode = (exec); \ 60 if (retCode) { \ 61 return ret; \ 62 } \ 63 } while (0) 64 #endif 65 66 #ifndef TRUE_RETURN_V_MSG_E 67 #define TRUE_RETURN_V_MSG_E(exec, ret, fmt, args...) \ 68 do { \ 69 bool retCode = (exec); \ 70 if (retCode) { \ 71 AVTRANS_LOGE(fmt, ##args); \ 72 return ret; \ 73 } \ 74 } while (0) 75 #endif 76 77 #ifndef TRUE_RETURN_V_MSG_D 78 #define TRUE_RETURN_V_MSG_D(exec, ret, fmt, args...) \ 79 do { \ 80 bool retCode = (exec); \ 81 if (retCode) { \ 82 AVTRANS_LOGD(fmt, ##args); \ 83 return ret; \ 84 } \ 85 } while (0) 86 #endif 87 88 #ifndef TRUE_LOG_MSG 89 #define TRUE_LOG_MSG(exec, fmt, args...) \ 90 do { \ 91 bool retCode = (exec); \ 92 if (retCode) { \ 93 AVTRANS_LOGE(fmt, ##args); \ 94 } \ 95 } while (0) 96 #endif 97 } // namespace DistributedHardware 98 } // namespace OHOS 99 #endif // OHOS_AV_TRANSPORT_LOG_H