• 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 SOFTBUS_ADAPTER_LOG_H
17 #define SOFTBUS_ADAPTER_LOG_H
18 
19 #include <stdio.h>
20 #include <stdbool.h>
21 
22 #ifndef SOFTBUS_DEBUG
23 #if defined(__LITEOS_M__)
24 #define SOFTBUS_PRINTF
25 #include "log.h"
26 #else
27 #include "hilog/log.h"
28 #endif
29 #endif
30 
31 #ifdef __cplusplus
32 #if __cplusplus
33 extern "C" {
34 #endif
35 #endif
36 
37 #ifndef SOFTBUS_DEBUG
38 #if defined(__LITEOS_M__)
39 
40 #define LOG_DBG(fmt, ...) HILOG_DEBUG(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
41 #define LOG_INFO(fmt, ...) HILOG_INFO(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
42 #define LOG_WARN(fmt, ...) HILOG_WARN(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
43 #define LOG_ERR(fmt, ...) HILOG_ERROR(HILOG_MODULE_SOFTBUS, fmt"\n", ##__VA_ARGS__);
44 #else
45 
46 #undef LOG_DOMAIN
47 #undef LOG_TAG
48 #define LOG_DOMAIN 0xD0015C0
49 #define LOG_TAG "dsoftbus"
50 
51 #define LOG_DBG(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt"\n", ##__VA_ARGS__);
52 #define LOG_INFO(fmt, ...) HILOG_INFO(LOG_CORE, fmt"\n", ##__VA_ARGS__);
53 #define LOG_WARN(fmt, ...) HILOG_WARN(LOG_CORE, fmt"\n", ##__VA_ARGS__);
54 #define LOG_ERR(fmt, ...) HILOG_ERROR(LOG_CORE, fmt"\n", ##__VA_ARGS__);
55 #endif
56 #else
57 enum {
58     SOFTBUS_LOG_LEVEL_DEBUG = 0,
59     SOFTBUS_LOG_LEVEL_INFO,
60     SOFTBUS_LOG_LEVEL_WARNING,
61     SOFTBUS_LOG_LEVEL_ERROR
62 };
63 
64 #define SOFTBUS_LOG_LEVEL SOFTBUS_LOG_LEVEL_INFO
65 
66 #define LOG_DBG(fmt, ...) do { \
67     if (SOFTBUS_LOG_LEVEL_DEBUG >= SOFTBUS_LOG_LEVEL) { \
68         printf("DEBUG:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
69     } \
70 } while (0)
71 
72 #define LOG_INFO(fmt, ...) do { \
73     if (SOFTBUS_LOG_LEVEL_INFO >= SOFTBUS_LOG_LEVEL) { \
74         printf("INFO:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
75     } \
76 } while (0)
77 
78 #define LOG_WARN(fmt, ...) do { \
79     if (SOFTBUS_LOG_LEVEL_WARNING >= SOFTBUS_LOG_LEVEL) { \
80         printf("WARN:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
81     } \
82 } while (0)
83 
84 #define LOG_ERR(fmt, ...) do { \
85     if (SOFTBUS_LOG_LEVEL_ERROR >= SOFTBUS_LOG_LEVEL) { \
86         printf("ERROR:%s:%d " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
87     } \
88 } while (0)
89 #endif
90 
91 #if defined(__LITEOS_M__)
92 #define SOFTBUS_HILOG_ID HILOG_MODULE_SOFTBUS
93 #else
94 #define SOFTBUS_HILOG_ID LOG_CORE
95 #endif
96 
97 typedef enum {
98     SOFTBUS_LOG_DBG,
99     SOFTBUS_LOG_INFO,
100     SOFTBUS_LOG_WARN,
101     SOFTBUS_LOG_ERROR,
102     SOFTBUS_LOG_LEVEL_MAX,
103 } SoftBusLogLevel;
104 
105 void SoftBusOutPrint(const char *buf, SoftBusLogLevel level);
106 
107 #ifdef __cplusplus
108 #if __cplusplus
109 }
110 #endif /* __cplusplus */
111 #endif /* __cplusplus */
112 
113 #endif
114