• 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 HKS_LOG_H
17 #define HKS_LOG_H
18 
19 #include "hks_type.h"
20 
21 #ifdef L2_STANDARD
22 #include "hks_error_msg.h"
23 #endif
24 
25 #ifdef HKS_CONFIG_FILE
26 #include HKS_CONFIG_FILE
27 #else
28 #include "hks_config.h"
29 #endif
30 
31 #ifdef _HUKS_LOG_ENABLE_
32 #ifdef HKS_ENABLE_LOG_PUBLIC
33 #define LOG_PUBLIC "{public}"
34 #else
35 #define LOG_PUBLIC
36 #endif
37 
38 #undef LOG_TAG
39 #define LOG_TAG "HUKS"
40 #undef LOG_DOMAIN
41 #define LOG_DOMAIN 0xD002F06 /* Security subsystem huks domain id */
42 
43 #ifdef HKS_LOG_ENGINE_LOG_CORE
44 #include "hilog/log.h"
45 #define LOG_ENGINE LOG_CORE
46 #else
47 #ifdef HKS_LOG_ENGINE_HILOG_MODULE_SCY
48 #include "log.h"
49 #define LOG_ENGINE HILOG_MODULE_SCY
50 #endif
51 #endif
52 
53 #ifdef L2_STANDARD
54 
55 enum HksLogLevel {
56     HKS_LOG_LEVEL_I,
57     HKS_LOG_LEVEL_E,
58     HKS_LOG_LEVEL_E_IMPORTANT,
59     HKS_LOG_LEVEL_W,
60     HKS_LOG_LEVEL_D,
61 };
62 
63 
64 #define HKS_LOG_I(fmt, arg...) HILOG_INFO(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
65                                                                                             __func__, __LINE__, ##arg)
66 #define HKS_LOG_W(fmt, arg...) HILOG_WARN(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
67                                                                                             __func__, __LINE__, ##arg)
68 #define HKS_LOG_E(fmt, arg...) \
69 do { \
70         HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg); \
71         HksLog(HKS_LOG_LEVEL_E, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt, __func__, __LINE__, ##arg); \
72 } while (0)
73 #define HKS_LOG_E_IMPORTANT(fmt, arg...) \
74 do { \
75         HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", __func__, __LINE__, ##arg); \
76         HksLog(HKS_LOG_LEVEL_E_IMPORTANT, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt, __func__, __LINE__, ##arg); \
77 } while (0)
78 #define HKS_LOG_D(fmt, arg...) HILOG_DEBUG(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
79                                                                                             __func__, __LINE__, ##arg)
80 
81 #else // L2_STANDARD
82 
83 #define HKS_LOG_I(fmt, arg...) HILOG_INFO(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
84                                                                                             __func__, __LINE__, ##arg)
85 #define HKS_LOG_W(fmt, arg...) HILOG_WARN(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
86                                                                                             __func__, __LINE__, ##arg)
87 #define HKS_LOG_E(fmt, arg...) HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
88                                                                                             __func__, __LINE__, ##arg)
89 #define HKS_LOG_E_IMPORTANT(fmt, arg...) HILOG_ERROR(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
90                                                                                             __func__, __LINE__, ##arg)
91 #define HKS_LOG_D(fmt, arg...) HILOG_DEBUG(LOG_ENGINE, "%" LOG_PUBLIC "s[%" LOG_PUBLIC "u]: " fmt "\n", \
92                                                                                             __func__, __LINE__, ##arg)
93 #endif // L2_STANDARD
94 
95 #else // _HUKS_LOG_ENABLE_
96 #define HKS_LOG_I(...)
97 #define HKS_LOG_W(...)
98 #define HKS_LOG_E(...)
99 #define HKS_LOG_E_IMPORTANT(...)
100 #define HKS_LOG_D(...)
101 #endif //_HUKS_LOG_ENABLE_
102 
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106 
107 extern uint32_t g_sessionId;
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif /* HKS_LOG_H */
114