• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef LOG_TAG
22 #define LOG_TAG "Bluetooth"
23 #endif
24 #include "hilog/log.h"
25 
26 #ifdef HILOGF
27 #undef HILOGF
28 #endif
29 
30 #ifdef HILOGE
31 #undef HILOGE
32 #endif
33 
34 #ifdef HILOGW
35 #undef HILOGW
36 #endif
37 
38 #ifdef HILOGI
39 #undef HILOGI
40 #endif
41 
42 #ifdef HILOGD
43 #undef HILOGD
44 #endif
45 
46 #define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
47 
48 #define HILOGD(fmt, ...)                 \
49     HILOG_DEBUG(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt,    \
50         __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
51 #define HILOGI(fmt, ...)                \
52     HILOG_INFO(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt,    \
53         __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
54 #define HILOGW(fmt, ...)                \
55     HILOG_WARN(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt,    \
56         __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
57 #define HILOGE(fmt, ...)                 \
58     HILOG_ERROR(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt,    \
59         __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
60 #define HILOGF(fmt, ...)                 \
61     HILOG_FATAL(LOG_CORE, "[%{public}s(%{public}s:%{public}d)]" fmt,    \
62         __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
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 #define CHECK_AND_RETURN_LOG_RET(cond, ret, fmt, ...)               \
73     do {                                                            \
74         if (!(cond)) {                                              \
75             HILOGE(fmt, ##__VA_ARGS__);    \
76             return ret;                                             \
77         }                                                           \
78     } while (0)
79 
80 #endif  // BLUETOOTH_LOG_H
81