16 #include <QLoggingCategory>
32 #define __FC_LINE__ __LINE__
35 bool log_init(
const QString &level_str = QStringLiteral(
"info"),
36 const QStringList &extra_rules = {});
41 #define log_base(level, message, ...) \
45 qFatal(message, ##__VA_ARGS__); \
48 qCritical(message, ##__VA_ARGS__); \
51 qWarning(message, ##__VA_ARGS__); \
54 qInfo(message, ##__VA_ARGS__); \
57 qDebug(message, ##__VA_ARGS__); \
63 #define log_debug(message, ...) qDebug(message, ##__VA_ARGS__)
65 #define log_debug(message, ...) \
71 #define log_test qInfo
72 #define log_packet qDebug
73 #define log_packet_detailed log_debug
74 #define LOG_TEST LOG_NORMAL
77 Q_DECLARE_LOGGING_CATEGORY(assert_category)
83 int line,
const char *
function,
84 const QString &
message = QString());
89 #define fc_assert(condition) \
92 : fc_assert_handle_failure(#condition, QT_MESSAGELOG_FILE, \
93 QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC))
96 #define fc_assert_msg(condition, message, ...) \
99 : fc_assert_handle_failure( \
100 #condition, QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, \
101 QT_MESSAGELOG_FUNC, QString::asprintf(message, ##__VA_ARGS__)))
104 #define fc_assert_action(condition, action) \
105 if (!(condition)) { \
106 fc_assert_handle_failure(#condition, QT_MESSAGELOG_FILE, \
107 QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC); \
112 #define fc_assert_ret(condition) fc_assert_action(condition, return )
114 #define fc_assert_ret_val(condition, val) \
115 fc_assert_action(condition, return val)
117 #define fc_assert_exit(condition) \
118 fc_assert_action(condition, exit(EXIT_FAILURE))
121 #define fc_assert_action_msg(condition, action, message, ...) \
122 if (!(condition)) { \
123 fc_assert_handle_failure(#condition, QT_MESSAGELOG_FILE, \
124 QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, \
125 QString::asprintf(message, ##__VA_ARGS__)); \
129 #define fc_assert_ret_msg(condition, message, ...) \
130 fc_assert_action_msg(condition, return, message, ##__VA_ARGS__)
132 #define fc_assert_ret_val_msg(condition, val, message, ...) \
133 fc_assert_action_msg(condition, return val, message, ##__VA_ARGS__)
135 #define fc_assert_exit_msg(condition, message, ...) \
136 fc_assert_action(condition, qFatal(message, ##__VA_ARGS__); \
140 #ifdef FREECIV_CXX11_STATIC_ASSERT
141 #define FC_STATIC_ASSERT(cond, tag) static_assert(cond, #tag)
144 #ifdef FREECIV_C11_STATIC_ASSERT
145 #define FC_STATIC_ASSERT(cond, tag) _Static_assert(cond, #tag)
147 #ifdef FREECIV_STATIC_STRLEN
148 #define FC_STATIC_STRLEN_ASSERT(cond, tag) FC_STATIC_ASSERT(cond, tag)
150 #define FC_STATIC_STRLEN_ASSERT(cond, tag)
154 #ifndef FC_STATIC_ASSERT
158 #define FC_STATIC_ASSERT(cond, tag) \
159 enum { static_assert_##tag = 1 / (!!(cond)) }
162 void log_time(
const QString &msg,
bool log =
false);
const QString & log_get_level()
Retrieves the log level passed to log_init (even if log_init failed).
bool log_init(const QString &level_str=QStringLiteral("info"), const QStringList &extra_rules={})
Parses a log level string as provided by the user on the command line, and installs the corresponding...
constexpr auto LOG_VERBOSE
constexpr auto LOG_NORMAL
void fc_assert_set_fatal(bool fatal_assertions)
Set what signal the assert* macros should raise on failed assertion (-1 to disable).
bool fc_assert_are_fatal()
Checks whether the fc_assert* macros should raise on failed assertion.
void log_set_file(const QString &path)
Redirects the log to a file.
void log_close()
Deinitialize logging module.
void log_time(const QString &msg, bool log=false)
void fc_assert_handle_failure(const char *condition, const char *file, int line, const char *function, const QString &message=QString())
Handles a failed assertion.