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 101 : static inline uint64_t GetTid(void)
30 : {
31 101 : const uint64_t tid = (uint64_t)(mmGetTaskId());
32 101 : return tid;
33 : }
34 :
35 : #ifdef RUN_TEST
36 : #define ACL_LOG_DEBUG(fmt, ...) \
37 : do { \
38 : printf("[DEBUG][%s:%d]%ld:" #fmt "\n", __FILE__, __LINE__, (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__, (long int)GetTid(), ##__VA_ARGS__); \
44 : } while (false)
45 :
46 : #define ACL_LOG_WARN(fmt, ...) \
47 : do { \
48 : printf("[WARNING][%s:%d]%ld:" #fmt "\n", __FILE__, __LINE__, (long int)GetTid(), ##__VA_ARGS__); \
49 : } while (false)
50 :
51 : #define ACL_LOG_EVENT(fmt, ...) \
52 : do { \
53 : printf("[EVENT][%s:%d]%ld:" #fmt "\n", __FILE__, __LINE__, (long int)GetTid(), ##__VA_ARGS__); \
54 : } while (false)
55 :
56 : #define ACL_LOG_ERROR(fmt, ...) \
57 : do { \
58 : printf( \
59 : "[ERROR][%s:%d]%ld:%s " #fmt "\n", __FILE__, __LINE__, (long int)GetTid(), ACL_GET_ERROR_LOG_HEADER, \
60 : ##__VA_ARGS__); \
61 : } while (false)
62 :
63 : #define ACL_LOG_INNER_ERROR(fmt, ...) \
64 : do { \
65 : printf( \
66 : "[ERROR][%s:%d]%ld:%s " #fmt "\n", __FILE__, __LINE__, (long int)GetTid(), ACL_REPORT_INNER_ERROR, \
67 : ##__VA_ARGS__); \
68 : } while (false)
69 :
70 : #define ACL_LOG_CALL_ERROR(fmt, ...) \
71 : do { \
72 : printf( \
73 : "[ERROR][%s:%d]%ld:%s " #fmt "\n", __FILE__, __LINE__, (long int)GetTid(), ACL_REPORT_CALL_ERROR, \
74 : ##__VA_ARGS__); \
75 : } while (false)
76 : #else
77 : #define ACL_LOG_DEBUG(fmt, ...) \
78 : do { \
79 : DlogRecord( \
80 : ACL_MODE_ID, DLOG_DEBUG, "[DEBUG][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, (long int)GetTid(), \
81 : ##__VA_ARGS__); \
82 : } while (false)
83 :
84 : #define ACL_LOG_INFO(fmt, ...) \
85 : do { \
86 : DlogRecord( \
87 : ACL_MODE_ID, DLOG_INFO, "[INFO][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, (long int)GetTid(), \
88 : ##__VA_ARGS__); \
89 : } while (false)
90 :
91 : #define ACL_LOG_WARN(fmt, ...) \
92 : do { \
93 : DlogRecord( \
94 : ACL_MODE_ID, DLOG_WARN, "[WARNING][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, (long int)GetTid(), \
95 : ##__VA_ARGS__); \
96 : } while (false)
97 :
98 : #define ACL_LOG_EVENT(fmt, ...) \
99 : do { \
100 : DlogRecord( \
101 : ACL_MODE_ID, DLOG_EVENT, "[Event][%s:%d]%ld " fmt "\n", __FILE__, __LINE__, (long int)GetTid(), \
102 : ##__VA_ARGS__); \
103 : } while (false)
104 :
105 : #define ACL_LOG_ERROR(fmt, ...) \
106 : do { \
107 : DlogRecord( \
108 : ACL_MODE_ID, DLOG_ERROR, "[ERROR][%s:%d]%ld:%s " fmt "\n", __FILE__, __LINE__, (long int)GetTid(), \
109 : ACL_GET_ERROR_LOG_HEADER, ##__VA_ARGS__); \
110 : } while (false)
111 :
112 : #define ACL_LOG_INNER_ERROR(fmt, ...) \
113 : do { \
114 : DlogRecord( \
115 : ACL_MODE_ID, DLOG_ERROR, "[ERROR][%s:%d]%ld:%s " fmt "\n", __FILE__, __LINE__, (long int)GetTid(), \
116 : ACL_REPORT_INNER_ERROR, ##__VA_ARGS__); \
117 : } while (false)
118 :
119 : #define ACL_LOG_CALL_ERROR(fmt, ...) \
120 : do { \
121 : DlogRecord( \
122 : ACL_MODE_ID, DLOG_ERROR, "[ERROR][%s:%d]%ld:%s " fmt "\n", __FILE__, __LINE__, (long int)GetTid(), \
123 : ACL_REPORT_CALL_ERROR, ##__VA_ARGS__); \
124 : } while (false)
125 : #endif
126 :
127 : #define ACL_REQUIRES_OK(expr) \
128 : do { \
129 : const aclError __ret = (expr); \
130 : if (__ret != ACL_SUCCESS) { \
131 : return __ret; \
132 : } \
133 : } while (false)
134 :
135 : #define ACL_CHECK_RANGE_INT(val, min, max) \
136 : do { \
137 : if (((val) < (min)) || ((val) > (max))) { \
138 : ACL_LOG_ERROR( \
139 : "[Check][%s]param:[%d] must be in range of [%d] and [%d]", #val, (int32_t)(val), (int32_t)(min), \
140 : (int32_t)(max)); \
141 : return ACL_ERROR_INVALID_PARAM; \
142 : } \
143 : } while (false)
144 :
145 : #define ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(val) \
146 : do { \
147 : if ((val) == NULL) { \
148 : ACL_LOG_ERROR("[Check][%s]param must not be NULL.", #val); \
149 : return ACL_ERROR_INVALID_PARAM; \
150 : } \
151 : } while (false)
152 :
153 : #define ACL_REQUIRES_NOT_NULL_RET_NULL_INPUT_REPORT(val) \
154 : do { \
155 : if ((val) == NULL) { \
156 : ACL_LOG_ERROR("[Check][%s]param must not be NULL.", #val); \
157 : return NULL; \
158 : } \
159 : } while (false)
160 :
161 : #define ACL_DELETE_AND_SET_NULL(var) \
162 : do { \
163 : if ((var) != NULL) { \
164 : mmFree(var); \
165 : (var) = NULL; \
166 : } \
167 : } while (false)
168 :
169 : #ifdef __cplusplus
170 : }
171 : #endif
172 : #endif // ACL_COMMON_LOG_INNER_H__
|