Blender  V2.93
CLG_log.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #ifndef __CLG_LOG_H__
18 #define __CLG_LOG_H__
19 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif /* __cplusplus */
74 
75 #ifdef __GNUC__
76 # define _CLOG_ATTR_NONNULL(args...) __attribute__((nonnull(args)))
77 #else
78 # define _CLOG_ATTR_NONNULL(...)
79 #endif
80 
81 #ifdef __GNUC__
82 # define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param) \
83  __attribute__((format(printf, format_param, dots_param)))
84 #else
85 # define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
86 #endif
87 
88 #define STRINGIFY_ARG(x) "" #x
89 #define STRINGIFY_APPEND(a, b) "" a #b
90 #define STRINGIFY(x) STRINGIFY_APPEND("", x)
91 
92 struct CLogContext;
93 
94 /* Don't typedef enums. */
96  CLG_FLAG_USE = (1 << 0),
97 };
98 
104 };
105 #define CLG_SEVERITY_LEN (CLG_SEVERITY_FATAL + 1)
106 
107 /* Each logger ID has one of these. */
108 typedef struct CLG_LogType {
109  struct CLG_LogType *next;
110  char identifier[64];
112  struct CLogContext *ctx;
114  int level;
115  enum CLG_LogFlag flag;
117 
118 typedef struct CLG_LogRef {
119  const char *identifier;
121  struct CLG_LogRef *next;
123 
125  enum CLG_Severity severity,
126  const char *file_line,
127  const char *fn,
128  const char *message) _CLOG_ATTR_NONNULL(1, 3, 4, 5);
130  enum CLG_Severity severity,
131  const char *file_line,
132  const char *fn,
133  const char *format,
135 
136 /* Main initializer and destructor (per session, not logger). */
137 void CLG_init(void);
138 void CLG_exit(void);
139 
140 void CLG_output_set(void *file_handle);
141 void CLG_output_use_basename_set(int value);
142 void CLG_output_use_timestamp_set(int value);
143 void CLG_error_fn_set(void (*error_fn)(void *file_handle));
144 void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle));
145 void CLG_backtrace_fn_set(void (*fatal_fn)(void *file_handle));
146 
147 void CLG_type_filter_include(const char *type_filter, int type_filter_len);
148 void CLG_type_filter_exclude(const char *type_filter, int type_filter_len);
149 
150 void CLG_level_set(int level);
151 
152 void CLG_logref_init(CLG_LogRef *clg_ref);
153 
154 int CLG_color_support_get(CLG_LogRef *clg_ref);
155 
157 #define CLG_LOGREF_DECLARE_GLOBAL(var, id) \
158  static CLG_LogRef _static_##var = {id}; \
159  CLG_LogRef *var = &_static_##var
160 
162 #define CLOG_ENSURE(clg_ref) \
163  ((clg_ref)->type ? (clg_ref)->type : (CLG_logref_init(clg_ref), (clg_ref)->type))
164 
165 #define CLOG_CHECK(clg_ref, verbose_level, ...) \
166  ((void)CLOG_ENSURE(clg_ref), \
167  ((clg_ref)->type->flag & CLG_FLAG_USE) && ((clg_ref)->type->level >= verbose_level))
168 
169 #define CLOG_AT_SEVERITY(clg_ref, severity, verbose_level, ...) \
170  { \
171  CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
172  if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
173  (severity >= CLG_SEVERITY_WARN)) { \
174  CLG_logf(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, __VA_ARGS__); \
175  } \
176  } \
177  ((void)0)
178 
179 #define CLOG_STR_AT_SEVERITY(clg_ref, severity, verbose_level, str) \
180  { \
181  CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
182  if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
183  (severity >= CLG_SEVERITY_WARN)) { \
184  CLG_log_str(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, str); \
185  } \
186  } \
187  ((void)0)
188 
189 #define CLOG_STR_AT_SEVERITY_N(clg_ref, severity, verbose_level, str) \
190  { \
191  CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
192  if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
193  (severity >= CLG_SEVERITY_WARN)) { \
194  const char *_str = str; \
195  CLG_log_str(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, _str); \
196  MEM_freeN((void *)_str); \
197  } \
198  } \
199  ((void)0)
200 
201 #define CLOG_INFO(clg_ref, level, ...) \
202  CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_INFO, level, __VA_ARGS__)
203 #define CLOG_WARN(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_WARN, 0, __VA_ARGS__)
204 #define CLOG_ERROR(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_ERROR, 0, __VA_ARGS__)
205 #define CLOG_FATAL(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_FATAL, 0, __VA_ARGS__)
206 
207 #define CLOG_STR_INFO(clg_ref, level, str) \
208  CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_INFO, level, str)
209 #define CLOG_STR_WARN(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_WARN, 0, str)
210 #define CLOG_STR_ERROR(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_ERROR, 0, str)
211 #define CLOG_STR_FATAL(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_FATAL, 0, str)
212 
213 /* Allocated string which is immediately freed. */
214 #define CLOG_STR_INFO_N(clg_ref, level, str) \
215  CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_INFO, level, str)
216 #define CLOG_STR_WARN_N(clg_ref, str) CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_WARN, 0, str)
217 #define CLOG_STR_ERROR_N(clg_ref, str) CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_ERROR, 0, str)
218 #define CLOG_STR_FATAL_N(clg_ref, str) CLOG_STR_AT_SEVERITY_N(clg_ref, CLG_SEVERITY_FATAL, 0, str)
219 
220 #ifdef __cplusplus
221 }
222 #endif
223 
224 #endif /* __CLG_LOG_H__ */
CLG_Severity
Definition: CLG_log.h:99
@ CLG_SEVERITY_INFO
Definition: CLG_log.h:100
@ CLG_SEVERITY_WARN
Definition: CLG_log.h:101
@ CLG_SEVERITY_FATAL
Definition: CLG_log.h:103
@ CLG_SEVERITY_ERROR
Definition: CLG_log.h:102
CLG_LogFlag
Definition: CLG_log.h:95
@ CLG_FLAG_USE
Definition: CLG_log.h:96
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:755
void CLG_output_set(void *file_handle)
Definition: clog.c:720
void CLG_output_use_basename_set(int value)
Definition: clog.c:725
void CLG_exit(void)
Definition: clog.c:715
void CLG_error_fn_set(void(*error_fn)(void *file_handle))
Definition: clog.c:735
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:745
#define _CLOG_ATTR_NONNULL(...)
Definition: CLG_log.h:78
struct CLG_LogType CLG_LogType
void CLG_type_filter_exclude(const char *type_filter, int type_filter_len)
Definition: clog.c:750
void CLG_fatal_fn_set(void(*fatal_fn)(void *file_handle))
Definition: clog.c:740
void CLG_logref_init(CLG_LogRef *clg_ref)
Definition: clog.c:773
#define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
Definition: CLG_log.h:85
void CLG_level_set(int level)
Definition: clog.c:760
void CLG_output_use_timestamp_set(int value)
Definition: clog.c:730
void CLG_init(void)
Definition: clog.c:708
int CLG_color_support_get(CLG_LogRef *clg_ref)
Definition: clog.c:799
format
Definition: logImageCore.h:47
const char * identifier
Definition: CLG_log.h:119
struct CLG_LogRef * next
Definition: CLG_log.h:121
CLG_LogType * type
Definition: CLG_log.h:120
char identifier[64]
Definition: CLG_log.h:110
struct CLG_LogType * next
Definition: CLG_log.h:109
enum CLG_LogFlag flag
Definition: CLG_log.h:115
struct CLogContext * ctx
Definition: CLG_log.h:112
int level
Definition: CLG_log.h:114