1/*
2 * Copyright (C) 2022 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 TELEPHONY_LOG_C_H
17#define TELEPHONY_LOG_C_H
18
19#include <stddef.h>
20
21#include "hilog/log.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#ifndef LOG_DOMAIN
28#define LOG_DOMAIN 0xD001F00
29#endif
30#ifndef LOG_TAG
31#define LOG_TAG "TelephonySubsystem"
32#endif
33
34#define OHOS_DEBUG
35#ifndef OHOS_DEBUG
36#define DECORATOR_HILOG(op, fmt, args...) \
37    do {                                  \
38        op(LOG_CORE, fmt, ##args);        \
39    } while (0)
40#else
41// Gets the raw file name of the file.
42// Its advantage is that it is executed only once __builtin_strrchr() function
43__attribute__((always_inline)) inline const char *GetRawFileName(const char *path)
44{
45    const char *last = __builtin_strrchr(path, '/');
46    return (last != NULL) ? (last + 1) : path;
47}
48
49#define DECORATOR_HILOG(op, fmt, args...)                                                                           \
50    do {                                                                                                            \
51        op(LOG_CORE, "[%{public}s-(%{public}s:%{public}d)] " fmt, __FUNCTION__, GetRawFileName(__FILE__), __LINE__, \
52            ##args);                                                                                                \
53    } while (0)
54#endif
55
56#define TELEPHONY_LOGE(fmt, args...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##args)
57#define TELEPHONY_LOGW(fmt, args...) DECORATOR_HILOG(HILOG_WARN, fmt, ##args)
58#define TELEPHONY_LOGI(fmt, args...) DECORATOR_HILOG(HILOG_INFO, fmt, ##args)
59#define TELEPHONY_LOGF(fmt, args...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##args)
60#define TELEPHONY_LOGD(fmt, args...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##args)
61
62#ifdef __cplusplus
63}
64#endif
65
66#endif // TELEPHONY_LOG_C_H
67