27#define MAX_LEN_LOG_LINE 5120
41#define __FC_LINE__ __LINE__
45#define NOLOGMSG nologmsg
49 const char *
where,
const char *msg);
59typedef const char *(*log_prefix_fn)(
void);
75 const char *file,
int line);
87#define log_do_output_for_level(level) \
88 log_do_output_for_level_at_location(level, __FILE__, __FC_LINE__)
90#define log_do_output_for_level(level) (log_get_level() >= level)
95#define log_base(level, message, ...) \
96 if (log_do_output_for_level(level)) { \
97 do_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, \
98 level, message, ## __VA_ARGS__); \
101#define log_fatal(message, ...) \
102 do_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, \
103 LOG_FATAL, message, ## __VA_ARGS__);
104#define log_error(message, ...) \
105 log_base(LOG_ERROR, message, ## __VA_ARGS__)
106#define log_warn(message, ...) \
107 log_base(LOG_WARN, message, ## __VA_ARGS__)
108#define log_normal(message, ...) \
109 log_base(LOG_NORMAL, message, ## __VA_ARGS__)
110#define log_verbose(message, ...) \
111 log_base(LOG_VERBOSE, message, ## __VA_ARGS__)
113# define log_debug(message, ...) \
114 log_base(LOG_DEBUG, message, ## __VA_ARGS__)
116# define log_debug(message, ...)
118#ifdef FREECIV_TESTMATIC
119#define log_testmatic(message, ...) \
120 log_base(LOG_ERROR, message, ## __VA_ARGS__)
121#define log_testmatic_alt(altlvl, message, ...) \
122 log_base(LOG_ERROR, message, ## __VA_ARGS__)
124#define log_testmatic(message, ...)
125#define log_testmatic_alt(altlvl, message, ...) \
126 log_base(altlvl, message, ## __VA_ARGS__)
129#define log_va_list(level, msg, args) \
130 if (log_do_output_for_level(level)) { \
132 vdo_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, \
133 level, __buf_, sizeof(__buf_), msg, args); \
137#define log_test log_normal
138#define log_packet log_verbose
139#define log_packet_detailed log_debug
140#define LOG_TEST LOG_NORMAL
147#define fc_assert_fail(...) (void) 0
154#define fc_assert_full(file, function, line, \
155 condition, action, message, ...) \
156 if (!(condition)) { \
157 fc_assert_fail(file, function, line, #condition, \
158 message, ## __VA_ARGS__); \
165#define fc_assert(...) (void) 0
166#define fc_assert_msg(...) (void) 0
167#define fc_assert_action(...) (void) 0
168#define fc_assert_ret(...) (void) 0
169#define fc_assert_ret_val(...) (void) 0
170#define fc_assert_exit(...) (void) 0
171#define fc_assert_action_msg(...) (void) 0
172#define fc_assert_ret_msg(...) (void) 0
173#define fc_assert_ret_val_msg(...) (void) 0
174#define fc_assert_exit_msg(...) (void) 0
177#define fc_assert(condition) \
178 ((condition) ? (void) 0 \
179 : fc_assert_fail(__FILE__, __FUNCTION__, __FC_LINE__, #condition, \
182#define fc_assert_msg(condition, message, ...) \
183 ((condition) ? (void) 0 \
184 : fc_assert_fail(__FILE__, __FUNCTION__, __FC_LINE__, \
185 #condition, message, ## __VA_ARGS__))
188#define fc_assert_action(condition, action) \
189 fc_assert_full(__FILE__, __FUNCTION__, __FC_LINE__, condition, action, \
192#define fc_assert_ret(condition) \
193 fc_assert_action(condition, return)
195#define fc_assert_ret_val(condition, val) \
196 fc_assert_action(condition, return val)
198#define fc_assert_exit(condition) \
199 fc_assert_action(condition, exit(EXIT_FAILURE))
202#define fc_assert_action_msg(condition, action, message, ...) \
203 fc_assert_full(__FILE__, __FUNCTION__, __FC_LINE__, condition, action, \
204 message, ## __VA_ARGS__)
206#define fc_assert_ret_msg(condition, message, ...) \
207 fc_assert_action_msg(condition, return, message, ## __VA_ARGS__)
209#define fc_assert_ret_val_msg(condition, val, message, ...) \
210 fc_assert_action_msg(condition, return val, message, ## __VA_ARGS__)
212#define fc_assert_exit_msg(condition, message, ...) \
213 fc_assert_action(condition, \
214 log_fatal(message, ## __VA_ARGS__); exit(EXIT_FAILURE))
218#ifdef FREECIV_CXX11_STATIC_ASSERT
219#define FC_STATIC_ASSERT(cond, tag) static_assert(cond, #tag)
222#ifdef FREECIV_C23_STATIC_ASSERT
223#define FC_STATIC_ASSERT(cond, tag) static_assert(cond, #tag)
224#elif defined(FREECIV_C11_STATIC_ASSERT)
225#define FC_STATIC_ASSERT(cond, tag) _Static_assert(cond, #tag)
227#ifdef FREECIV_STATIC_STRLEN
228#define FC_STATIC_STRLEN_ASSERT(cond, tag) FC_STATIC_ASSERT(cond, tag)
230#define FC_STATIC_STRLEN_ASSERT(cond, tag)
234#ifndef FC_STATIC_ASSERT
238#define FC_STATIC_ASSERT(cond, tag) \
239 enum { static_assert_ ## tag = 1 / (!!(cond)) }
void fc_assert_fail(const char *file, const char *function, int line, const char *assertion, const char *message,...) fc__attribute((__format__(__printf__
const char *(* log_prefix_fn)(void)
void(* log_callback_fn)(enum log_level, const char *, bool file_too)
void log_init(const char *filename, enum log_level initial_level, log_callback_fn callback, log_prefix_fn prefix, int fatal_assertions)
void fc_assert_set_fatal(int fatal_assertions)
void do_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, const char *message,...) fc__attribute((__format__(__printf__
void log_set_level(enum log_level level)
void(* log_pre_callback_fn)(enum log_level, bool print_from_where, const char *where, const char *msg)
log_callback_fn log_set_callback(log_callback_fn callback)
const char * log_level_name(enum log_level lvl)
log_pre_callback_fn log_set_pre_callback(log_pre_callback_fn precallback)
void vdo_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, char *buf, int buflen, const char *message, va_list args)
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
log_prefix_fn log_set_prefix(log_prefix_fn prefix)
enum log_level log_get_level(void)
static int fatal_assertions
struct setting_list * level[OLEVELS_NUM]