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