111fccf17Sopenharmony_ci/* 211fccf17Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 311fccf17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 411fccf17Sopenharmony_ci * you may not use this file except in compliance with the License. 511fccf17Sopenharmony_ci * You may obtain a copy of the License at 611fccf17Sopenharmony_ci * 711fccf17Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 811fccf17Sopenharmony_ci * 911fccf17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1011fccf17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1111fccf17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1211fccf17Sopenharmony_ci * See the License for the specific language governing permissions and 1311fccf17Sopenharmony_ci * limitations under the License. 1411fccf17Sopenharmony_ci */ 1511fccf17Sopenharmony_ci 1611fccf17Sopenharmony_ci#ifndef TELEPHONY_LOG_WRAPPER_H 1711fccf17Sopenharmony_ci#define TELEPHONY_LOG_WRAPPER_H 1811fccf17Sopenharmony_ci 1911fccf17Sopenharmony_ci#include <string> 2011fccf17Sopenharmony_ci 2111fccf17Sopenharmony_ci#include "hilog/log.h" 2211fccf17Sopenharmony_ci 2311fccf17Sopenharmony_cinamespace OHOS { 2411fccf17Sopenharmony_cinamespace Telephony { 2511fccf17Sopenharmony_ci#ifndef LOG_DOMAIN 2611fccf17Sopenharmony_ci#define LOG_DOMAIN 0xD001F00 2711fccf17Sopenharmony_ci#endif 2811fccf17Sopenharmony_ci#ifndef TELEPHONY_LOG_TAG 2911fccf17Sopenharmony_ci#define TELEPHONY_LOG_TAG "TelephonySubsystem" 3011fccf17Sopenharmony_ci#endif 3111fccf17Sopenharmony_ci 3211fccf17Sopenharmony_ci#define OHOS_DEBUG 3311fccf17Sopenharmony_ci#ifndef OHOS_DEBUG 3411fccf17Sopenharmony_ci#define TELEPHONY_LOGE(fmt, ...) \ 3511fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 3611fccf17Sopenharmony_ci#define TELEPHONY_LOGW(fmt, ...) \ 3711fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 3811fccf17Sopenharmony_ci#define TELEPHONY_LOGI(fmt, ...) \ 3911fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 4011fccf17Sopenharmony_ci#define TELEPHONY_LOGF(fmt, ...) \ 4111fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 4211fccf17Sopenharmony_ci#define TELEPHONY_LOGD(fmt, ...) \ 4311fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, TELEPHONY_LOG_TAG, fmt, ##__VA_ARGS__) 4411fccf17Sopenharmony_ci#else 4511fccf17Sopenharmony_ci// Gets the raw file name of the file. 4611fccf17Sopenharmony_ci// This function is a function executed by the compiler, that is, 4711fccf17Sopenharmony_ci// it has been executed at compile time. When the program runs, 4811fccf17Sopenharmony_ci// it directly refers to the value calculated by this function 4911fccf17Sopenharmony_ci// and does not consume CPU for calculation. 5011fccf17Sopenharmony_ciinline constexpr const char *GetRawFileName(const char *path) 5111fccf17Sopenharmony_ci{ 5211fccf17Sopenharmony_ci char ch = '/'; 5311fccf17Sopenharmony_ci const char *start = path; 5411fccf17Sopenharmony_ci // get the end of the string 5511fccf17Sopenharmony_ci while (*start++) { 5611fccf17Sopenharmony_ci ; 5711fccf17Sopenharmony_ci } 5811fccf17Sopenharmony_ci while (--start != path && *start != ch) { 5911fccf17Sopenharmony_ci ; 6011fccf17Sopenharmony_ci } 6111fccf17Sopenharmony_ci 6211fccf17Sopenharmony_ci return (*start == ch) ? ++start : path; 6311fccf17Sopenharmony_ci} 6411fccf17Sopenharmony_ci 6511fccf17Sopenharmony_ci#define TELEPHONY_LOGE(fmt, ...) \ 6611fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_ERROR, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 6711fccf17Sopenharmony_ci __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 6811fccf17Sopenharmony_ci#define TELEPHONY_LOGW(fmt, ...) \ 6911fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_WARN, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 7011fccf17Sopenharmony_ci __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 7111fccf17Sopenharmony_ci#define TELEPHONY_LOGI(fmt, ...) \ 7211fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_INFO, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 7311fccf17Sopenharmony_ci __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 7411fccf17Sopenharmony_ci#define TELEPHONY_LOGF(fmt, ...) \ 7511fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_FATAL, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 7611fccf17Sopenharmony_ci __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 7711fccf17Sopenharmony_ci#define TELEPHONY_LOGD(fmt, ...) \ 7811fccf17Sopenharmony_ci (void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, TELEPHONY_LOG_TAG, "[%{public}s-(%{public}s:%{public}d)] " fmt, \ 7911fccf17Sopenharmony_ci __FUNCTION__, GetRawFileName(__FILE__), __LINE__, ##__VA_ARGS__) 8011fccf17Sopenharmony_ci#endif 8111fccf17Sopenharmony_ci} // namespace Telephony 8211fccf17Sopenharmony_ci} // namespace OHOS 8311fccf17Sopenharmony_ci#endif // OHOS_TELEPHONY_LOG_WRAPPER_H 84