Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 : #ifndef ACL_COMMON_LOG_INNER_H__
11 : #define ACL_COMMON_LOG_INNER_H__
12 :
13 : #include "acl/acl_base.h"
14 : #include "error_manager.h"
15 : #include "dlog_pub.h"
16 : #include "mmpa_api.h"
17 :
18 : #ifdef __cplusplus
19 : extern "C" {
20 : #endif
21 :
22 : #define ACL_GET_ERROR_LOG_HEADER "[ACL][MODULE]"
23 : #define ACL_REPORT_INNER_ERROR "REPORT_INNER_ERROR"
24 : #define ACL_REPORT_CALL_ERROR "REPORT_CALL_ERROR"
25 : #define ACL_MODE_ID ((int32_t)(ASCENDCL))
26 : #define INVALID_PARAM_MSG "EH0001"
27 : #define INVALID_NULL_POINTER_MSG "EH0002"
28 :
29 96 : static inline uint64_t GetTid(void) {
30 96 : const uint64_t tid = (uint64_t)(mmGetTaskId());
31 96 : return tid;
32 : }
33 :
34 : #ifdef RUN_TEST
35 : #define ACL_LOG_DEBUG(fmt, ...) \
36 : do { \
37 : printf("[DEBUG][%s:%d]%ld:" #fmt "\n", __FILE__, __LINE__, \
38 : (long int)GetTid(), ##__VA_ARGS__); \
39 : } while (false)
40 :
41 : #define ACL_LOG_INFO(fmt, ...) \
42 : do { \
43 : printf("[INFO][%s:%d]%ld:" #fmt "\n", __FILE__, __LINE__, \
44 : (long int)GetTid(), ##__VA_ARGS__); \
45 : } while (false)
46 :
47 : #define ACL_LOG_WARN(fmt, ...) \
48 : do { \
49 : printf("[WARNING][%s:%d]%ld:" #fmt "\n", __FILE__, __LINE__, \
50 : (long int)GetTid(), ##__VA_ARGS__); \
51 : } while (false)
52 :
53 : #define ACL_LOG_EVENT(fmt, ...) \
54 : do { \
55 : printf("[EVENT][%s:%d]%ld:" #fmt "\n", __FILE__, __LINE__, \
56 : (long int)GetTid(), ##__VA_ARGS__); \
57 : } while (false)
58 :
59 : #define ACL_LOG_ERROR(fmt, ...) \
60 : do { \
61 : printf("[ERROR][%s:%d]%ld:%s " #fmt "\n", __FILE__, __LINE__, \
62 : (long int)GetTid(), ACL_GET_ERROR_LOG_HEADER, ##__VA_ARGS__); \
63 : } while (false)
64 :
65 : #define ACL_LOG_INNER_ERROR(fmt, ...) \
66 : do { \
67 : printf("[ERROR][%s:%d]%ld:%s " #fmt "\n", __FILE__, __LINE__, \
68 : (long int)GetTid(), ACL_REPORT_INNER_ERROR, ##__VA_ARGS__); \
69 : } while (false)
70 :
71 : #define ACL_LOG_CALL_ERROR(fmt, ...) \
72 : do { \
73 : printf("[ERROR][%s:%d]%ld:%s " #fmt "\n", __FILE__, __LINE__, \
74 : (long int)GetTid(), ACL_REPORT_CALL_ERROR, ##__VA_ARGS__); \
75 : } while (false)
76 : #else
77 : #define ACL_LOG_DEBUG(fmt, ...) \
78 : do { \
79 : DlogRecord(ACL_MODE_ID, DLOG_DEBUG, "[DEBUG][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, \
80 : (long int)GetTid(), ##__VA_ARGS__); \
81 : } while (false)
82 :
83 : #define ACL_LOG_INFO(fmt, ...) \
84 : do { \
85 : DlogRecord(ACL_MODE_ID, DLOG_INFO, "[INFO][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, \
86 : (long int)GetTid(), ##__VA_ARGS__); \
87 : } while (false)
88 :
89 : #define ACL_LOG_WARN(fmt, ...) \
90 : do { \
91 : DlogRecord(ACL_MODE_ID, DLOG_WARN, "[WARNING][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, \
92 : (long int)GetTid(), ##__VA_ARGS__); \
93 : } while (false)
94 :
95 : #define ACL_LOG_EVENT(fmt, ...) \
96 : do { \
97 : DlogRecord(ACL_MODE_ID, DLOG_EVENT, "[Event][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, \
98 : (long int)GetTid(), ##__VA_ARGS__); \
99 : } while (false)
100 :
101 : #define ACL_LOG_ERROR(fmt, ...) \
102 : do { \
103 : DlogRecord(ACL_MODE_ID, DLOG_ERROR, "[ERROR][%s:%d]%ld:%s " fmt "\n", __FILE__, __LINE__, \
104 : (long int)GetTid(), ACL_GET_ERROR_LOG_HEADER, ##__VA_ARGS__); \
105 : } while (false)
106 :
107 : #define ACL_LOG_INNER_ERROR(fmt, ...) \
108 : do { \
109 : DlogRecord(ACL_MODE_ID, DLOG_ERROR, "[ERROR][%s:%d]%ld:%s " fmt "\n", __FILE__, __LINE__, \
110 : (long int)GetTid(), ACL_REPORT_INNER_ERROR, ##__VA_ARGS__); \
111 : } while (false)
112 :
113 : #define ACL_LOG_CALL_ERROR(fmt, ...) \
114 : do { \
115 : DlogRecord(ACL_MODE_ID, DLOG_ERROR, "[ERROR][%s:%d]%ld:%s " fmt "\n", __FILE__, __LINE__, \
116 : (long int)GetTid(), ACL_REPORT_CALL_ERROR, ##__VA_ARGS__); \
117 : } while (false)
118 : #endif
119 :
120 : #define ACL_REQUIRES_OK(expr) \
121 : do { \
122 : const aclError __ret = (expr); \
123 : if (__ret != ACL_SUCCESS) { \
124 : return __ret; \
125 : } \
126 : } while (false)
127 :
128 : #define ACL_CHECK_RANGE_INT(val, min, max) \
129 : do { \
130 : if (((val) < (min)) || ((val) > (max))) { \
131 : ACL_LOG_ERROR("[Check][%s]param:[%d] must be in range of [%d] and [%d]", \
132 : #val, (int32_t)(val), (int32_t)(min), (int32_t)(max)); \
133 : return ACL_ERROR_INVALID_PARAM; \
134 : } \
135 : } while (false)
136 :
137 : #define ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(val) \
138 : do { \
139 : if ((val) == NULL) { \
140 : ACL_LOG_ERROR("[Check][%s]param must not be NULL.", #val); \
141 : return ACL_ERROR_INVALID_PARAM; \
142 : } \
143 : } while (false)
144 :
145 : #define ACL_REQUIRES_NOT_NULL_RET_NULL_INPUT_REPORT(val) \
146 : do { \
147 : if ((val) == NULL) { \
148 : ACL_LOG_ERROR("[Check][%s]param must not be NULL.", #val); \
149 : return NULL; \
150 : } \
151 : } while (false)
152 :
153 : #define ACL_DELETE_AND_SET_NULL(var) \
154 : do { \
155 : if ((var) != NULL) { \
156 : mmFree(var); \
157 : (var) = NULL; \
158 : } \
159 : } while (false)
160 :
161 : #ifdef __cplusplus
162 : }
163 : #endif
164 : #endif // ACL_COMMON_LOG_INNER_H__
|