1 /* 2 * Copyright (c) 2021-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_TELEPHONY_LOG_WRAPPER_H 17 #define OHOS_TELEPHONY_LOG_WRAPPER_H 18 19 #include <string> 20 21 #include "hilog/log.h" 22 23 namespace OHOS { 24 namespace Telephony { 25 #define CONFIG_HILOG 26 #ifdef CONFIG_HILOG 27 28 #ifndef TELEPHONY_LOG_TAG 29 #define TELEPHONY_LOG_TAG "TelephonySubsystem" 30 #endif 31 32 #ifndef TELEPHONY_LOG_FUNC_NAME 33 #define TELEPHONY_LOG_FUNC_NAME __func__ 34 #endif 35 36 #define OHOS_DEBUG 37 #ifndef OHOS_DEBUG 38 #define TELEPHONY_LOGE(fmt, ...) \ 39 (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 40 #define TELEPHONY_LOGW(fmt, ...) \ 41 (void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 42 #define TELEPHONY_LOGI(fmt, ...) \ 43 (void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 44 #define TELEPHONY_LOGF(fmt, ...) \ 45 (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 46 #define TELEPHONY_LOGD(fmt, ...) \ 47 (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 48 #else 49 // Gets the raw file name of the file. 50 // This function is a function executed by the compiler, that is, 51 // it has been executed at compile time. When the program runs, 52 // it directly refers to the value calculated by this function 53 // and does not consume CPU for calculation. 54 inline constexpr const char *GetRawFileName(const char *path) 55 { 56 char ch = '/'; 57 const char *start = path; 58 // get the end of the string 59 while (*start++) { 60 ; 61 } 62 while (--start != path && *start != ch) { 63 ; 64 } 65 66 return (*start == ch) ? ++start : path; 67 } 68 69 #define TELEPHONY_LOGE(fmt, ...) \ 70 (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 71 __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 72 #define TELEPHONY_LOGW(fmt, ...) \ 73 (void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 74 __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 75 #define TELEPHONY_LOGI(fmt, ...) \ 76 (void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 77 __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 78 #define TELEPHONY_LOGF(fmt, ...) \ 79 (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 80 __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 81 #define TELEPHONY_LOGD(fmt, ...) \ 82 (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 83 __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 84 #endif 85 #endif // CONFIG_HILOG 86 } // namespace Telephony 87 } // namespace OHOS 88 #endif // OHOS_TELEPHONY_LOG_WRAPPER_H 89