1 /* 2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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_SHARING_LOG_H 17 #define OHOS_SHARING_LOG_H 18 19 #include <cinttypes> 20 #include "hilog/log.h" 21 22 namespace OHOS { 23 namespace Sharing { 24 #ifndef SHARING_LOG_TAG 25 #define SHARING_LOG_TAG "sharing" 26 #endif 27 28 #ifndef SHARING_LOG_DOMAIN 29 #define SHARING_LOG_DOMAIN 0xD002B09 30 #define SHARING_SERVICE_TEMP_SA_ID 5527 31 #define SHARING_SERVICE_DOMAIN_TEMP_SA_ID 5528 32 #endif 33 34 static constexpr OHOS::HiviewDFX::HiLogLabel SHARING_LABEL = {LOG_CORE, SHARING_LOG_DOMAIN, SHARING_LOG_TAG}; 35 36 #define R_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 37 38 #define SHARING_LOG(func, fmt, args...) \ 39 do { \ 40 (void)func(SHARING_LABEL, "[Sharing][%{public}s()][%{public}s:%{public}d] " fmt, __FUNCTION__, R_FILENAME, \ 41 __LINE__, ##args); \ 42 } while (0) 43 44 #define SHARING_LOGD(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Debug, fmt, ##__VA_ARGS__) 45 #define SHARING_LOGI(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Info, fmt, ##__VA_ARGS__) 46 #define SHARING_LOGW(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Warn, fmt, ##__VA_ARGS__) 47 #define SHARING_LOGE(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Error, fmt, ##__VA_ARGS__) 48 #define SHARING_LOGF(fmt, ...) SHARING_LOG(OHOS::HiviewDFX::HiLog::Fatal, fmt, ##__VA_ARGS__) 49 50 #define CHECK_AND_RETURN(cond) \ 51 do { \ 52 if (!(cond)) { \ 53 SHARING_LOGE("%{public}s, check failed!", #cond); \ 54 return; \ 55 } \ 56 } while (0) 57 58 #define CHECK_AND_RETURN_RET(cond, ret) \ 59 do { \ 60 if (!(cond)) { \ 61 SHARING_LOGE("%{public}s, check failed! ret: %{public}s.", #cond, #ret); \ 62 return ret; \ 63 } \ 64 } while (0) 65 66 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 67 do { \ 68 if (!(cond)) { \ 69 SHARING_LOGE(fmt, ##__VA_ARGS__); \ 70 return ret; \ 71 } \ 72 } while (0) 73 74 #define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 75 do { \ 76 if (!(cond)) { \ 77 SHARING_LOGE(fmt, ##__VA_ARGS__); \ 78 return; \ 79 } \ 80 } while (0) 81 82 } // namespace Sharing 83 } // namespace OHOS 84 #endif