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 OHOS_IPC_RPC_LOG_H
17 #define OHOS_IPC_RPC_LOG_H
18 
19 #include <stdio.h>
20 #include <stdbool.h>
21 
22 #ifndef IPCRPC_DEBUG
23 #if defined(__LITEOS_M__)
24 #define IPCRPC_PRINTF
25 #include "log.h"
26 #else
27 #include "hilog/log.h"
28 #endif
29 #endif
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef IPCRPC_DEBUG
36 #if defined(__LITEOS_M__)
37 #define RPC_LOG_DEBUG(fmt, ...)  HILOG_DEBUG(HILOG_MODULE_SOFTBUS, fmt, ##__VA_ARGS__)
38 #define RPC_LOG_INFO(fmt, ...)   HILOG_INFO(HILOG_MODULE_SOFTBUS, fmt, ##__VA_ARGS__)
39 #define RPC_LOG_WARN(fmt, ...)   HILOG_WARN(HILOG_MODULE_SOFTBUS, fmt, ##__VA_ARGS__)
40 #define RPC_LOG_ERROR(fmt, ...)  HILOG_ERROR(HILOG_MODULE_SOFTBUS, fmt, ##__VA_ARGS__)
41 #else
42 #undef LOG_DOMAIN
43 #undef LOG_TAG
44 #define LOG_DOMAIN 0xD001518
45 #define LOG_TAG "IPCRPC"
46 
47 #define RPC_LOG_DEBUG(fmt, ...) HILOG_DEBUG(LOG_CORE, fmt, ##__VA_ARGS__)
48 #define RPC_LOG_INFO(fmt, ...)  HILOG_INFO(LOG_CORE, fmt, ##__VA_ARGS__)
49 #define RPC_LOG_WARN(fmt, ...)  HILOG_WARN(LOG_CORE, fmt, ##__VA_ARGS__)
50 #define RPC_LOG_ERROR(fmt, ...) HILOG_ERROR(LOG_CORE, fmt, ##__VA_ARGS__)
51 #endif
52 #else
53 enum {
54     RPC_LOG_LEVEL_DEBUG = 0,
55     RPC_LOG_LEVEL_INFO,
56     RPC_LOG_LEVEL_WARNING,
57     RPC_LOG_LEVEL_ERROR
58 };
59 
60 #define RPC_LOG_LEVEL RPC_LOG_LEVEL_INFO
61 
62 #define LOG_DBG(fmt, ...) do { \
63     if (RPC_LOG_LEVEL_DEBUG >= RPC_LOG_LEVEL) { \
64         printf("DEBUG: " fmt "\n", ##__VA_ARGS__); \
65     } \
66 } while (0)
67 
68 #define LOG_INFO(fmt, ...) do { \
69     if (RPC_LOG_LEVEL_INFO >= RPC_LOG_LEVEL) { \
70         printf("INFO: " fmt "\n", ##__VA_ARGS__); \
71     } \
72 } while (0)
73 
74 #define LOG_WARN(fmt, ...) do { \
75     if (RPC_LOG_LEVEL_WARNING >= RPC_LOG_LEVEL) { \
76         printf("WARN: " fmt "\n", ##__VA_ARGS__); \
77     } \
78 } while (0)
79 
80 #define LOG_ERR(fmt, ...) do { \
81     if (RPC_LOG_LEVEL_ERROR >= RPC_LOG_LEVEL) { \
82         printf("ERROR: " fmt "\n", ##__VA_ARGS__); \
83     } \
84 } while (0)
85 #endif
86 
87 #if defined(__LITEOS_M__)
88 #define RPC_HILOG_ID HILOG_MODULE_SOFTBUS
89 #else
90 #define RPC_HILOG_ID LOG_CORE
91 #endif
92 
93 typedef enum {
94     RPC_LOG_DBG,
95     RPC_LOG_INFO,
96     RPC_LOG_WARN,
97     RPC_LOG_ERROR,
98     RPC_LOG_LEVEL_MAX,
99 } RpcLogLevel;
100 
101 typedef enum {
102     RPC_LOG_IPC,
103     RPC_LOG_RPC,
104     RPC_LOG_SER,
105     RPC_LOG_MODULE_MAX,
106 } RpcLogModule;
107 
108 void RpcLog(RpcLogModule module, RpcLogLevel level, const char *fmt, ...);
109 
110 #ifdef __cplusplus
111 }
112 #endif /* __cplusplus */
113 #endif /* OHOS_IPC_RPC_LOG_H */