Blender  V3.3
CLG_log.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
54 #ifndef __CLG_LOG_H__
55 #define __CLG_LOG_H__
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif /* __cplusplus */
60 
61 #ifdef __GNUC__
62 # define _CLOG_ATTR_NONNULL(args...) __attribute__((nonnull(args)))
63 #else
64 # define _CLOG_ATTR_NONNULL(...)
65 #endif
66 
67 #ifdef __GNUC__
68 # define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param) \
69  __attribute__((format(printf, format_param, dots_param)))
70 #else
71 # define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
72 #endif
73 
74 #define STRINGIFY_ARG(x) "" #x
75 #define STRINGIFY_APPEND(a, b) "" a #b
76 #define STRINGIFY(x) STRINGIFY_APPEND("", x)
77 
78 struct CLogContext;
79 
80 /* Don't typedef enums. */
82  CLG_FLAG_USE = (1 << 0),
83 };
84 
90 };
91 #define CLG_SEVERITY_LEN (CLG_SEVERITY_FATAL + 1)
92 
93 /* Each logger ID has one of these. */
94 typedef struct CLG_LogType {
95  struct CLG_LogType *next;
96  char identifier[64];
98  struct CLogContext *ctx;
100  int level;
101  enum CLG_LogFlag flag;
103 
104 typedef struct CLG_LogRef {
105  const char *identifier;
107  struct CLG_LogRef *next;
109 
111  enum CLG_Severity severity,
112  const char *file_line,
113  const char *fn,
114  const char *message) _CLOG_ATTR_NONNULL(1, 3, 4, 5);
116  enum CLG_Severity severity,
117  const char *file_line,
118  const char *fn,
119  const char *format,
121 
122 /* Main initializer and destructor (per session, not logger). */
123 void CLG_init(void);
124 void CLG_exit(void);
125 
126 void CLG_output_set(void *file_handle);
127 void CLG_output_use_basename_set(int value);
128 void CLG_output_use_timestamp_set(int value);
129 void CLG_error_fn_set(void (*error_fn)(void *file_handle));
130 void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle));
131 void CLG_backtrace_fn_set(void (*fatal_fn)(void *file_handle));
132 
133 void CLG_type_filter_include(const char *type_filter, int type_filter_len);
134 void CLG_type_filter_exclude(const char *type_filter, int type_filter_len);
135 
136 void CLG_level_set(int level);
137 
138 void CLG_logref_init(CLG_LogRef *clg_ref);
139 
140 int CLG_color_support_get(CLG_LogRef *clg_ref);
141 
143 #define CLG_LOGREF_DECLARE_GLOBAL(var, id) \
144  static CLG_LogRef _static_##var = {id}; \
145  CLG_LogRef *var = &_static_##var
146 
148 #define CLOG_ENSURE(clg_ref) \
149  ((clg_ref)->type ? (clg_ref)->type : (CLG_logref_init(clg_ref), (clg_ref)->type))
150 
151 #define CLOG_CHECK(clg_ref, verbose_level, ...) \
152  ((void)CLOG_ENSURE(clg_ref), \
153  ((clg_ref)->type->flag & CLG_FLAG_USE) && ((clg_ref)->type->level >= verbose_level))
154 
155 #define CLOG_AT_SEVERITY(clg_ref, severity, verbose_level, ...) \
156  { \
157  CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
158  if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
159  (severity >= CLG_SEVERITY_WARN)) { \
160  CLG_logf(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, __VA_ARGS__); \
161  } \
162  } \
163  ((void)0)
164 
165 #define CLOG_STR_AT_SEVERITY(clg_ref, severity, verbose_level, str) \
166  { \
167  CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
168  if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
169  (severity >= CLG_SEVERITY_WARN)) { \
170  CLG_log_str(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, str); \
171  } \
172  } \
173  ((void)0)
174 
175 #define CLOG_STR_AT_SEVERITY_N(clg_ref, severity, verbose_level, str) \
176  { \
177  CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
178  if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
179  (severity >= CLG_SEVERITY_WARN)) { \
180  const char *_str = str; \
181  CLG_log_str(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, _str); \
182  MEM_freeN((void *)_str); \
183  } \
184  } \
185  ((void)0)
186 
187 #define CLOG_INFO(clg_ref, level, ...) \
188  CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_INFO, level, __VA_ARGS__)
189 #define CLOG_WARN(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_WARN, 0, __VA_ARGS__)
190 #define CLOG_ERROR(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_ERROR, 0, __VA_ARGS__)
191 #define CLOG_FATAL(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_FATAL, 0, __VA_ARGS__)
192 
193 #define CLOG_STR_INFO(clg_ref, level, str) \
194  CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_INFO, level, str)
195 #define CLOG_STR_WARN(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_WARN, 0, str)
196 #define CLOG_STR_ERROR(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_ERROR, 0, str)
197 #define CLOG_STR_FATAL(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_FATAL, 0, str)
198 
199 /* Allocated string which is immediately freed. */
200 #define CLOG_STR_INFO_N(clg_ref, level, str) \
201  CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_INFO, level, str)
202 #define CLOG_STR_WARN_N(clg_ref, str) CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_WARN, 0, str)
203 #define CLOG_STR_ERROR_N(clg_ref, str) CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_ERROR, 0, str)
204 #define CLOG_STR_FATAL_N(clg_ref, str) CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_FATAL, 0, str)
205 
206 #ifdef __cplusplus
207 }
208 #endif
209 
210 #endif /* __CLG_LOG_H__ */
CLG_Severity
Definition: CLG_log.h:85
@ CLG_SEVERITY_INFO
Definition: CLG_log.h:86
@ CLG_SEVERITY_WARN
Definition: CLG_log.h:87
@ CLG_SEVERITY_FATAL
Definition: CLG_log.h:89
@ CLG_SEVERITY_ERROR
Definition: CLG_log.h:88
CLG_LogFlag
Definition: CLG_log.h:81
@ CLG_FLAG_USE
Definition: CLG_log.h:82
void void CLG_logf(CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *format,...) _CLOG_ATTR_NONNULL(1
void CLG_type_filter_include(const char *type_filter, int type_filter_len)
Definition: clog.c:743
void CLG_output_set(void *file_handle)
Definition: clog.c:708
void CLG_output_use_basename_set(int value)
Definition: clog.c:713
void CLG_exit(void)
Definition: clog.c:703
void CLG_error_fn_set(void(*error_fn)(void *file_handle))
Definition: clog.c:723
struct CLG_LogRef CLG_LogRef
void CLG_log_str(CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *message) _CLOG_ATTR_NONNULL(1
void CLG_backtrace_fn_set(void(*fatal_fn)(void *file_handle))
Definition: clog.c:733
#define _CLOG_ATTR_NONNULL(...)
Definition: CLG_log.h:64
struct CLG_LogType CLG_LogType
void CLG_type_filter_exclude(const char *type_filter, int type_filter_len)
Definition: clog.c:738
void CLG_fatal_fn_set(void(*fatal_fn)(void *file_handle))
Definition: clog.c:728
void CLG_logref_init(CLG_LogRef *clg_ref)
Definition: clog.c:761
#define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
Definition: CLG_log.h:71
void CLG_level_set(int level)
Definition: clog.c:748
void CLG_output_use_timestamp_set(int value)
Definition: clog.c:718
void CLG_init(void)
Definition: clog.c:696
int CLG_color_support_get(CLG_LogRef *clg_ref)
Definition: clog.c:787
format
Definition: logImageCore.h:38
const char * identifier
Definition: CLG_log.h:105
struct CLG_LogRef * next
Definition: CLG_log.h:107
CLG_LogType * type
Definition: CLG_log.h:106
char identifier[64]
Definition: CLG_log.h:96
struct CLG_LogType * next
Definition: CLG_log.h:95
enum CLG_LogFlag flag
Definition: CLG_log.h:101
struct CLogContext * ctx
Definition: CLG_log.h:98
int level
Definition: CLG_log.h:100