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 
16 #ifndef BLUETOOTH_LOG_H
17 #define BLUETOOTH_LOG_H
18 
19 #undef LOG_DOMAIN
20 #define LOG_DOMAIN 0xD000101
21 
22 #include "hilog/log.h"
23 
24 #ifdef HILOGF
25 #undef HILOGF
26 #endif
27 
28 #ifdef HILOGE
29 #undef HILOGE
30 #endif
31 
32 #ifdef HILOGW
33 #undef HILOGW
34 #endif
35 
36 #ifdef HILOGI
37 #undef HILOGI
38 #endif
39 
40 #ifdef HILOGD
41 #undef HILOGD
42 #endif
43 
44 #define HILOGD(fmt, ...)                 \
45     HILOG_DEBUG(LOG_CORE, "(%{public}s:%{public}d)" fmt,    \
46         __FUNCTION__, __LINE__, ##__VA_ARGS__)
47 #define HILOGI(fmt, ...)                \
48     HILOG_INFO(LOG_CORE, "(%{public}s:%{public}d)" fmt,    \
49         __FUNCTION__, __LINE__, ##__VA_ARGS__)
50 #define HILOGW(fmt, ...)                \
51     HILOG_WARN(LOG_CORE, "(%{public}s:%{public}d)" fmt,    \
52         __FUNCTION__, __LINE__, ##__VA_ARGS__)
53 #define HILOGE(fmt, ...)                 \
54     HILOG_ERROR(LOG_CORE, "(%{public}s:%{public}d)" fmt,    \
55         __FUNCTION__, __LINE__, ##__VA_ARGS__)
56 #define HILOGF(fmt, ...)                 \
57     HILOG_FATAL(LOG_CORE, "(%{public}s:%{public}d)" fmt,    \
58         __FUNCTION__, __LINE__, ##__VA_ARGS__)
59 
60 #ifdef CHECK_AND_RETURN_LOG
61 #undef CHECK_AND_RETURN_LOG
62 #endif
63 
64 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)        \
65     do {                                            \
66         if (!(cond)) {                              \
67             HILOGE(fmt, ##__VA_ARGS__);             \
68             return;                                 \
69         }                                           \
70     } while (0)
71 
72 #ifdef CHECK_AND_RETURN_LOG_RET
73 #undef CHECK_AND_RETURN_LOG_RET
74 #endif
75 
76 #define CHECK_AND_RETURN_LOG_RET(cond, ret, fmt, ...)               \
77     do {                                                            \
78         if (!(cond)) {                                              \
79             HILOGE(fmt, ##__VA_ARGS__);                             \
80             return ret;                                             \
81         }                                                           \
82     } while (0)
83 
84 #endif  // BLUETOOTH_LOG_H
85