Blender V4.3
CLG_log.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
56#ifndef __CLG_LOG_H__
57#define __CLG_LOG_H__
58
59#ifdef __cplusplus
60extern "C" {
61#endif /* __cplusplus */
62
63#ifdef __GNUC__
64# define _CLOG_ATTR_NONNULL(args...) __attribute__((nonnull(args)))
65#else
66# define _CLOG_ATTR_NONNULL(...)
67#endif
68
69#ifdef __GNUC__
70# define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param) \
71 __attribute__((format(printf, format_param, dots_param)))
72#else
73# define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
74#endif
75
76#define STRINGIFY_ARG(x) "" #x
77#define STRINGIFY_APPEND(a, b) "" a #b
78#define STRINGIFY(x) STRINGIFY_APPEND("", x)
79
80struct CLogContext;
81
82/* Don't typedef enums. */
84 CLG_FLAG_USE = (1 << 0),
85};
86
93#define CLG_SEVERITY_LEN (CLG_SEVERITY_FATAL + 1)
94
95/* Each logger ID has one of these. */
96typedef struct CLG_LogType {
98 char identifier[64];
102 int level;
105
111
113 enum CLG_Severity severity,
114 const char *file_line,
115 const char *fn,
116 const char *message) _CLOG_ATTR_NONNULL(1, 3, 4, 5);
117void CLG_logf(const CLG_LogType *lg,
118 enum CLG_Severity severity,
119 const char *file_line,
120 const char *fn,
121 const char *format,
123
124/* Main initializer and destructor (per session, not logger). */
125void CLG_init(void);
126void CLG_exit(void);
127
128void CLG_output_set(void *file_handle);
129void CLG_output_use_basename_set(int value);
130void CLG_output_use_timestamp_set(int value);
131void CLG_error_fn_set(void (*error_fn)(void *file_handle));
132void CLG_fatal_fn_set(void (*fatal_fn)(void *file_handle));
133void CLG_backtrace_fn_set(void (*fatal_fn)(void *file_handle));
134
135void CLG_type_filter_include(const char *type_match, int type_match_len);
136void CLG_type_filter_exclude(const char *type_match, int type_match_len);
137
138void CLG_level_set(int level);
139
140void CLG_logref_init(CLG_LogRef *clg_ref);
141
143
145#define CLG_LOGREF_DECLARE_GLOBAL(var, id) \
146 static CLG_LogRef _static_##var = {id}; \
147 CLG_LogRef *var = &_static_##var
148
150#define CLOG_ENSURE(clg_ref) \
151 ((clg_ref)->type ? (clg_ref)->type : (CLG_logref_init(clg_ref), (clg_ref)->type))
152
153#define CLOG_CHECK(clg_ref, verbose_level, ...) \
154 ((void)CLOG_ENSURE(clg_ref), \
155 ((clg_ref)->type->flag & CLG_FLAG_USE) && ((clg_ref)->type->level >= verbose_level))
156
157#define CLOG_AT_SEVERITY(clg_ref, severity, verbose_level, ...) \
158 { \
159 const CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
160 if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
161 (severity >= CLG_SEVERITY_WARN)) \
162 { \
163 CLG_logf(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, __VA_ARGS__); \
164 } \
165 } \
166 ((void)0)
167
168#define CLOG_STR_AT_SEVERITY(clg_ref, severity, verbose_level, str) \
169 { \
170 const CLG_LogType *_lg_ty = CLOG_ENSURE(clg_ref); \
171 if (((_lg_ty->flag & CLG_FLAG_USE) && (_lg_ty->level >= verbose_level)) || \
172 (severity >= CLG_SEVERITY_WARN)) \
173 { \
174 CLG_log_str(_lg_ty, severity, __FILE__ ":" STRINGIFY(__LINE__), __func__, str); \
175 } \
176 } \
177 ((void)0)
178
179#define CLOG_INFO(clg_ref, level, ...) \
180 CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_INFO, level, __VA_ARGS__)
181#define CLOG_WARN(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_WARN, 0, __VA_ARGS__)
182#define CLOG_ERROR(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_ERROR, 0, __VA_ARGS__)
183#define CLOG_FATAL(clg_ref, ...) CLOG_AT_SEVERITY(clg_ref, CLG_SEVERITY_FATAL, 0, __VA_ARGS__)
184
185#define CLOG_STR_INFO(clg_ref, level, str) \
186 CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_INFO, level, str)
187#define CLOG_STR_WARN(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_WARN, 0, str)
188#define CLOG_STR_ERROR(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_ERROR, 0, str)
189#define CLOG_STR_FATAL(clg_ref, str) CLOG_STR_AT_SEVERITY(clg_ref, CLG_SEVERITY_FATAL, 0, str)
190
191#ifdef __cplusplus
192}
193#endif
194
195#endif /* __CLG_LOG_H__ */
void CLG_log_str(const CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *message) _CLOG_ATTR_NONNULL(1
CLG_Severity
Definition CLG_log.h:87
@ CLG_SEVERITY_INFO
Definition CLG_log.h:88
@ CLG_SEVERITY_WARN
Definition CLG_log.h:89
@ CLG_SEVERITY_FATAL
Definition CLG_log.h:91
@ CLG_SEVERITY_ERROR
Definition CLG_log.h:90
CLG_LogFlag
Definition CLG_log.h:83
@ CLG_FLAG_USE
Definition CLG_log.h:84
void CLG_type_filter_exclude(const char *type_match, int type_match_len)
Definition clog.c:741
void CLG_output_set(void *file_handle)
Definition clog.c:711
void CLG_output_use_basename_set(int value)
Definition clog.c:716
void CLG_exit(void)
Definition clog.c:706
void void CLG_logf(const CLG_LogType *lg, enum CLG_Severity severity, const char *file_line, const char *fn, const char *format,...) _CLOG_ATTR_NONNULL(1
void CLG_error_fn_set(void(*error_fn)(void *file_handle))
Definition clog.c:726
struct CLG_LogRef CLG_LogRef
void CLG_backtrace_fn_set(void(*fatal_fn)(void *file_handle))
Definition clog.c:736
#define _CLOG_ATTR_NONNULL(...)
Definition CLG_log.h:66
struct CLG_LogType CLG_LogType
void CLG_fatal_fn_set(void(*fatal_fn)(void *file_handle))
Definition clog.c:731
void CLG_type_filter_include(const char *type_match, int type_match_len)
Definition clog.c:746
void CLG_logref_init(CLG_LogRef *clg_ref)
Definition clog.c:764
#define _CLOG_ATTR_PRINTF_FORMAT(format_param, dots_param)
Definition CLG_log.h:73
void CLG_level_set(int level)
Definition clog.c:751
void CLG_output_use_timestamp_set(int value)
Definition clog.c:721
void CLG_init(void)
Definition clog.c:699
int CLG_color_support_get(CLG_LogRef *clg_ref)
Definition clog.c:790
format
const char * identifier
Definition CLG_log.h:107
struct CLG_LogRef * next
Definition CLG_log.h:109
CLG_LogType * type
Definition CLG_log.h:108
struct CLG_LogType * next
Definition CLG_log.h:97
enum CLG_LogFlag flag
Definition CLG_log.h:103
struct CLogContext * ctx
Definition CLG_log.h:100