111fccf17Sopenharmony_ci/* 211fccf17Sopenharmony_ci * Copyright (C) 2022 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_C_H 1711fccf17Sopenharmony_ci#define TELEPHONY_LOG_C_H 1811fccf17Sopenharmony_ci 1911fccf17Sopenharmony_ci#include <stddef.h> 2011fccf17Sopenharmony_ci 2111fccf17Sopenharmony_ci#include "hilog/log.h" 2211fccf17Sopenharmony_ci 2311fccf17Sopenharmony_ci#ifdef __cplusplus 2411fccf17Sopenharmony_ciextern "C" { 2511fccf17Sopenharmony_ci#endif 2611fccf17Sopenharmony_ci 2711fccf17Sopenharmony_ci#ifndef LOG_DOMAIN 2811fccf17Sopenharmony_ci#define LOG_DOMAIN 0xD001F00 2911fccf17Sopenharmony_ci#endif 3011fccf17Sopenharmony_ci#ifndef LOG_TAG 3111fccf17Sopenharmony_ci#define LOG_TAG "TelephonySubsystem" 3211fccf17Sopenharmony_ci#endif 3311fccf17Sopenharmony_ci 3411fccf17Sopenharmony_ci#define OHOS_DEBUG 3511fccf17Sopenharmony_ci#ifndef OHOS_DEBUG 3611fccf17Sopenharmony_ci#define DECORATOR_HILOG(op, fmt, args...) \ 3711fccf17Sopenharmony_ci do { \ 3811fccf17Sopenharmony_ci op(LOG_CORE, fmt, ##args); \ 3911fccf17Sopenharmony_ci } while (0) 4011fccf17Sopenharmony_ci#else 4111fccf17Sopenharmony_ci// Gets the raw file name of the file. 4211fccf17Sopenharmony_ci// Its advantage is that it is executed only once __builtin_strrchr() function 4311fccf17Sopenharmony_ci__attribute__((always_inline)) inline const char *GetRawFileName(const char *path) 4411fccf17Sopenharmony_ci{ 4511fccf17Sopenharmony_ci const char *last = __builtin_strrchr(path, '/'); 4611fccf17Sopenharmony_ci return (last != NULL) ? (last + 1) : path; 4711fccf17Sopenharmony_ci} 4811fccf17Sopenharmony_ci 4911fccf17Sopenharmony_ci#define DECORATOR_HILOG(op, fmt, args...) \ 5011fccf17Sopenharmony_ci do { \ 5111fccf17Sopenharmony_ci op(LOG_CORE, "[%{public}s-(%{public}s:%{public}d)] " fmt, __FUNCTION__, GetRawFileName(__FILE__), __LINE__, \ 5211fccf17Sopenharmony_ci ##args); \ 5311fccf17Sopenharmony_ci } while (0) 5411fccf17Sopenharmony_ci#endif 5511fccf17Sopenharmony_ci 5611fccf17Sopenharmony_ci#define TELEPHONY_LOGE(fmt, args...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##args) 5711fccf17Sopenharmony_ci#define TELEPHONY_LOGW(fmt, args...) DECORATOR_HILOG(HILOG_WARN, fmt, ##args) 5811fccf17Sopenharmony_ci#define TELEPHONY_LOGI(fmt, args...) DECORATOR_HILOG(HILOG_INFO, fmt, ##args) 5911fccf17Sopenharmony_ci#define TELEPHONY_LOGF(fmt, args...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##args) 6011fccf17Sopenharmony_ci#define TELEPHONY_LOGD(fmt, args...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##args) 6111fccf17Sopenharmony_ci 6211fccf17Sopenharmony_ci#ifdef __cplusplus 6311fccf17Sopenharmony_ci} 6411fccf17Sopenharmony_ci#endif 6511fccf17Sopenharmony_ci 6611fccf17Sopenharmony_ci#endif // TELEPHONY_LOG_C_H 67