xref: /aosp_15_r20/external/pytorch/aten/src/ATen/native/quantized/cpu/qnnpack/deps/clog/include/clog.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <inttypes.h>
12 #include <stdarg.h>
13 #include <stdlib.h>
14 
15 #define CLOG_NONE 0
16 #define CLOG_FATAL 1
17 #define CLOG_ERROR 2
18 #define CLOG_WARNING 3
19 #define CLOG_INFO 4
20 #define CLOG_DEBUG 5
21 
22 #ifndef CLOG_VISIBILITY
23 #if defined(__ELF__)
24 #define CLOG_VISIBILITY __attribute__((__visibility__("internal")))
25 #elif defined(__MACH__)
26 #define CLOG_VISIBILITY __attribute__((__visibility__("hidden")))
27 #else
28 #define CLOG_VISIBILITY
29 #endif
30 #endif
31 
32 #ifndef CLOG_ARGUMENTS_FORMAT
33 #if defined(__GNUC__)
34 #define CLOG_ARGUMENTS_FORMAT __attribute__((__format__(__printf__, 1, 2)))
35 #else
36 #define CLOG_ARGUMENTS_FORMAT
37 #endif
38 #endif
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 CLOG_VISIBILITY void clog_vlog_debug(
45     const char* module,
46     const char* format,
47     va_list args);
48 CLOG_VISIBILITY void clog_vlog_info(
49     const char* module,
50     const char* format,
51     va_list args);
52 CLOG_VISIBILITY void clog_vlog_warning(
53     const char* module,
54     const char* format,
55     va_list args);
56 CLOG_VISIBILITY void clog_vlog_error(
57     const char* module,
58     const char* format,
59     va_list args);
60 CLOG_VISIBILITY void clog_vlog_fatal(
61     const char* module,
62     const char* format,
63     va_list args);
64 
65 #define CLOG_DEFINE_LOG_DEBUG(log_debug_function_name, module, level)   \
66   CLOG_ARGUMENTS_FORMAT                                                 \
67   inline static void log_debug_function_name(const char* format, ...) { \
68     if (level >= CLOG_DEBUG) {                                          \
69       va_list args;                                                     \
70       va_start(args, format);                                           \
71       clog_vlog_debug(module, format, args);                            \
72       va_end(args);                                                     \
73     }                                                                   \
74   }
75 
76 #define CLOG_DEFINE_LOG_INFO(log_info_function_name, module, level)    \
77   CLOG_ARGUMENTS_FORMAT                                                \
78   inline static void log_info_function_name(const char* format, ...) { \
79     if (level >= CLOG_INFO) {                                          \
80       va_list args;                                                    \
81       va_start(args, format);                                          \
82       clog_vlog_info(module, format, args);                            \
83       va_end(args);                                                    \
84     }                                                                  \
85   }
86 
87 #define CLOG_DEFINE_LOG_WARNING(log_warning_function_name, module, level) \
88   CLOG_ARGUMENTS_FORMAT                                                   \
89   inline static void log_warning_function_name(const char* format, ...) { \
90     if (level >= CLOG_WARNING) {                                          \
91       va_list args;                                                       \
92       va_start(args, format);                                             \
93       clog_vlog_warning(module, format, args);                            \
94       va_end(args);                                                       \
95     }                                                                     \
96   }
97 
98 #define CLOG_DEFINE_LOG_ERROR(log_error_function_name, module, level)   \
99   CLOG_ARGUMENTS_FORMAT                                                 \
100   inline static void log_error_function_name(const char* format, ...) { \
101     if (level >= CLOG_ERROR) {                                          \
102       va_list args;                                                     \
103       va_start(args, format);                                           \
104       clog_vlog_error(module, format, args);                            \
105       va_end(args);                                                     \
106     }                                                                   \
107   }
108 
109 #define CLOG_DEFINE_LOG_FATAL(log_fatal_function_name, module, level)   \
110   CLOG_ARGUMENTS_FORMAT                                                 \
111   inline static void log_fatal_function_name(const char* format, ...) { \
112     if (level >= CLOG_FATAL) {                                          \
113       va_list args;                                                     \
114       va_start(args, format);                                           \
115       clog_vlog_fatal(module, format, args);                            \
116       va_end(args);                                                     \
117     }                                                                   \
118     abort();                                                            \
119   }
120 
121 #ifdef __cplusplus
122 } /* extern "C" */
123 #endif
124