1 /* 2 * Copyright (c) 2021 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 #ifndef PASTEBOARD_HILOG_H 16 #define PASTEBOARD_HILOG_H 17 18 #include "hilog/log.h" 19 20 namespace OHOS { 21 namespace MiscServices { 22 // param of log interface, such as PASTEBOARD_HILOGF. 23 enum PasteboardSubModule { 24 PASTEBOARD_MODULE_INNERKIT = 0, 25 PASTEBOARD_MODULE_CLIENT, 26 PASTEBOARD_MODULE_SERVICE, 27 PASTEBOARD_MODULE_JAVAKIT, // java kit, defined to avoid repeated use of domain. 28 PASTEBOARD_MODULE_JNI, 29 PASTEBOARD_MODULE_COMMON, 30 PASTEBOARD_MODULE_JS_NAPI, 31 PASTEBOARD_MODULE_CAPI, 32 PASTEBOARD_MODULE_JS_ANI, 33 PASTEBOARD_MODULE_BUTT, 34 }; 35 36 // 0xD001C00: subsystem:PASTEBOARD module:PasteboardManager, 8 bits reserved. 37 static constexpr unsigned int BASE_PASTEBOARD_DOMAIN_ID = 0xD001C00; 38 39 enum PasteboardDomainId { 40 PASTEBOARD_INNERKIT_DOMAIN = BASE_PASTEBOARD_DOMAIN_ID + PASTEBOARD_MODULE_INNERKIT, 41 PASTEBOARD_CLIENT_DOMAIN, 42 PASTEBOARD_SERVICE_DOMAIN, 43 PASTEBOARD_JAVAKIT_DOMAIN, 44 PASTEBOARD_JNI_DOMAIN, 45 PASTEBOARD_COMMON_DOMAIN, 46 PASTEBOARD_JS_NAPI, 47 PASTEBOARD_CAPI, 48 PASTEBOARD_JS_ANI, 49 PASTEBOARD_BUTT, 50 }; 51 52 static constexpr OHOS::HiviewDFX::HiLogLabel PASTEBOARD[PASTEBOARD_MODULE_BUTT] = { 53 { LOG_CORE, PASTEBOARD_INNERKIT_DOMAIN, "PBIK" }, 54 { LOG_CORE, PASTEBOARD_CLIENT_DOMAIN, "PBC" }, 55 { LOG_CORE, PASTEBOARD_SERVICE_DOMAIN, "PBS" }, 56 { LOG_CORE, PASTEBOARD_JAVAKIT_DOMAIN, "PBJK" }, 57 { LOG_CORE, PASTEBOARD_JNI_DOMAIN, "PBJN" }, 58 { LOG_CORE, PASTEBOARD_COMMON_DOMAIN, "PBCM" }, 59 { LOG_CORE, PASTEBOARD_JS_NAPI, "PBJS" }, 60 { LOG_CORE, PASTEBOARD_CAPI, "PBCA" }, 61 { LOG_CORE, PASTEBOARD_JS_ANI, "PBANI" }, 62 }; 63 64 // In order to improve performance, do not check the module range. 65 // Besides, make sure module is less than PASTEBOARD_MODULE_BUTT. 66 #define PASTEBOARD_HILOGF(module, ...) \ 67 do { \ 68 if (HiLogIsLoggable(PASTEBOARD[module].domain, PASTEBOARD[module].tag, LOG_FATAL)) { \ 69 ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, PASTEBOARD[module].domain, PASTEBOARD[module].tag, \ 70 "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__)); \ 71 } \ 72 } while (0) 73 #define PASTEBOARD_HILOGE(module, fmt, ...) \ 74 do { \ 75 if (HiLogIsLoggable(PASTEBOARD[module].domain, PASTEBOARD[module].tag, LOG_ERROR)) { \ 76 ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, PASTEBOARD[module].domain, PASTEBOARD[module].tag, \ 77 "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__)); \ 78 } \ 79 } while (0) 80 #define PASTEBOARD_HILOGW(module, fmt, ...) \ 81 do { \ 82 if (HiLogIsLoggable(PASTEBOARD[module].domain, PASTEBOARD[module].tag, LOG_WARN)) { \ 83 ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, PASTEBOARD[module].domain, PASTEBOARD[module].tag, \ 84 "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__)); \ 85 } \ 86 } while (0) 87 #define PASTEBOARD_HILOGI(module, fmt, ...) \ 88 do { \ 89 if (HiLogIsLoggable(PASTEBOARD[module].domain, PASTEBOARD[module].tag, LOG_INFO)) { \ 90 ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, PASTEBOARD[module].domain, PASTEBOARD[module].tag, \ 91 "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__)); \ 92 } \ 93 } while (0) 94 #define PASTEBOARD_HILOGD(module, fmt, ...) \ 95 do { \ 96 if (HiLogIsLoggable(PASTEBOARD[module].domain, PASTEBOARD[module].tag, LOG_DEBUG)) { \ 97 ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, PASTEBOARD[module].domain, PASTEBOARD[module].tag, \ 98 "%{public}s# " fmt, __FUNCTION__, ##__VA_ARGS__)); \ 99 } \ 100 } while (0) 101 102 // check then return ret and print log 103 #define CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, log, label, fmt, ...) \ 104 do { \ 105 if (!(cond)) { \ 106 log(label, fmt, ##__VA_ARGS__); \ 107 return ret; \ 108 } \ 109 } while (0) 110 111 // check then return and print log 112 #define CHECK_AND_RETURN_LOG_INNER(cond, log, label, fmt, ...) \ 113 do { \ 114 if (!(cond)) { \ 115 log(label, fmt, ##__VA_ARGS__); \ 116 return; \ 117 } \ 118 } while (0) 119 120 #define PASTEBOARD_CHECK_AND_RETURN_RET_LOGD(cond, ret, label, fmt, ...) \ 121 CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, PASTEBOARD_HILOGD, label, fmt, ##__VA_ARGS__) 122 #define PASTEBOARD_CHECK_AND_RETURN_RET_LOGI(cond, ret, label, fmt, ...) \ 123 CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, PASTEBOARD_HILOGI, label, fmt, ##__VA_ARGS__) 124 #define PASTEBOARD_CHECK_AND_RETURN_RET_LOGW(cond, ret, label, fmt, ...) \ 125 CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, PASTEBOARD_HILOGW, label, fmt, ##__VA_ARGS__) 126 #define PASTEBOARD_CHECK_AND_RETURN_RET_LOGE(cond, ret, label, fmt, ...) \ 127 CHECK_AND_RETURN_RET_LOG_INNER(cond, ret, PASTEBOARD_HILOGE, label, fmt, ##__VA_ARGS__) 128 #define PASTEBOARD_CHECK_AND_RETURN_LOGD(cond, label, fmt, ...) \ 129 CHECK_AND_RETURN_LOG_INNER(cond, PASTEBOARD_HILOGD, label, fmt, ##__VA_ARGS__) 130 #define PASTEBOARD_CHECK_AND_RETURN_LOGI(cond, label, fmt, ...) \ 131 CHECK_AND_RETURN_LOG_INNER(cond, PASTEBOARD_HILOGI, label, fmt, ##__VA_ARGS__) 132 #define PASTEBOARD_CHECK_AND_RETURN_LOGW(cond, label, fmt, ...) \ 133 CHECK_AND_RETURN_LOG_INNER(cond, PASTEBOARD_HILOGW, label, fmt, ##__VA_ARGS__) 134 #define PASTEBOARD_CHECK_AND_RETURN_LOGE(cond, label, fmt, ...) \ 135 CHECK_AND_RETURN_LOG_INNER(cond, PASTEBOARD_HILOGE, label, fmt, ##__VA_ARGS__) 136 137 } // namespace MiscServices 138 } // namespace OHOS 139 140 #endif // PASTEBOARD_HILOG_H 141