Freeciv21
Develop your civilization from humble roots to a global empire
log.h File Reference
#include <QLoggingCategory>
#include <QString>
#include <QtGlobal>
#include <stdlib.h>
+ Include dependency graph for log.h:

Go to the source code of this file.

Macros

#define __FC_LINE__   __LINE__
 
#define log_base(level, message, ...)
 
#define log_debug(message, ...)
 
#define log_test   qInfo
 
#define log_packet   qDebug
 
#define log_packet_detailed   log_debug
 
#define LOG_TEST   LOG_NORMAL
 
#define fc_assert(condition)
 
#define fc_assert_msg(condition, message, ...)
 
#define fc_assert_action(condition, action)
 
#define fc_assert_ret(condition)   fc_assert_action(condition, return )
 
#define fc_assert_ret_val(condition, val)    fc_assert_action(condition, return val)
 
#define fc_assert_exit(condition)    fc_assert_action(condition, exit(EXIT_FAILURE))
 
#define fc_assert_action_msg(condition, action, message, ...)
 
#define fc_assert_ret_msg(condition, message, ...)    fc_assert_action_msg(condition, return, message, ##__VA_ARGS__)
 
#define fc_assert_ret_val_msg(condition, val, message, ...)    fc_assert_action_msg(condition, return val, message, ##__VA_ARGS__)
 
#define fc_assert_exit_msg(condition, message, ...)
 
#define FC_STATIC_STRLEN_ASSERT(cond, tag)
 
#define FC_STATIC_ASSERT(cond, tag)    enum { static_assert_##tag = 1 / (!!(cond)) }
 

Functions

void log_close ()
 Deinitialize logging module. More...
 
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 Qt log filters. More...
 
void log_set_file (const QString &path)
 Redirects the log to a file. More...
 
const QString & log_get_level ()
 Retrieves the log level passed to log_init (even if log_init failed). More...
 
void fc_assert_set_fatal (bool fatal_assertions)
 Set what signal the assert* macros should raise on failed assertion (-1 to disable). More...
 
bool fc_assert_are_fatal ()
 Checks whether the fc_assert* macros should raise on failed assertion. More...
 
void fc_assert_handle_failure (const char *condition, const char *file, int line, const char *function, const QString &message=QString())
 Handles a failed assertion. More...
 
void log_time (const QString &msg, bool log=false)
 

Variables

constexpr auto LOG_FATAL = QtFatalMsg
 
constexpr auto LOG_ERROR = QtCriticalMsg
 
constexpr auto LOG_WARN = QtWarningMsg
 
constexpr auto LOG_NORMAL = QtInfoMsg
 
constexpr auto LOG_VERBOSE = QtDebugMsg
 
constexpr auto LOG_DEBUG = QtDebugMsg
 

Macro Definition Documentation

◆ __FC_LINE__

#define __FC_LINE__   __LINE__

Definition at line 32 of file log.h.

◆ fc_assert

#define fc_assert (   condition)
Value:
((condition) \
? ((void) 0) \
: fc_assert_handle_failure(#condition, QT_MESSAGELOG_FILE, \
QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC))
void fc_assert_handle_failure(const char *condition, const char *file, int line, const char *function, const QString &message=QString())
Handles a failed assertion.
Definition: log.cpp:236

Definition at line 89 of file log.h.

◆ fc_assert_action

#define fc_assert_action (   condition,
  action 
)
Value:
if (!(condition)) { \
fc_assert_handle_failure(#condition, QT_MESSAGELOG_FILE, \
QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC); \
action; \
}

Definition at line 104 of file log.h.

◆ fc_assert_action_msg

#define fc_assert_action_msg (   condition,
  action,
  message,
  ... 
)
Value:
if (!(condition)) { \
fc_assert_handle_failure(#condition, QT_MESSAGELOG_FILE, \
QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, \
QString::asprintf(message, ##__VA_ARGS__)); \
action; \
}

Definition at line 121 of file log.h.

◆ fc_assert_exit

#define fc_assert_exit (   condition)     fc_assert_action(condition, exit(EXIT_FAILURE))

Definition at line 117 of file log.h.

◆ fc_assert_exit_msg

#define fc_assert_exit_msg (   condition,
  message,
  ... 
)
Value:
fc_assert_action(condition, qFatal(message, ##__VA_ARGS__); \
exit(EXIT_FAILURE))
#define fc_assert_action(condition, action)
Definition: log.h:104

Definition at line 135 of file log.h.

◆ fc_assert_msg

#define fc_assert_msg (   condition,
  message,
  ... 
)
Value:
((condition) \
? ((void) 0) \
#condition, QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, \
QT_MESSAGELOG_FUNC, QString::asprintf(message, ##__VA_ARGS__)))

Definition at line 96 of file log.h.

◆ fc_assert_ret

#define fc_assert_ret (   condition)    fc_assert_action(condition, return )

Definition at line 112 of file log.h.

◆ fc_assert_ret_msg

#define fc_assert_ret_msg (   condition,
  message,
  ... 
)     fc_assert_action_msg(condition, return, message, ##__VA_ARGS__)

Definition at line 129 of file log.h.

◆ fc_assert_ret_val

#define fc_assert_ret_val (   condition,
  val 
)     fc_assert_action(condition, return val)

Definition at line 114 of file log.h.

◆ fc_assert_ret_val_msg

#define fc_assert_ret_val_msg (   condition,
  val,
  message,
  ... 
)     fc_assert_action_msg(condition, return val, message, ##__VA_ARGS__)

Definition at line 132 of file log.h.

◆ FC_STATIC_ASSERT

#define FC_STATIC_ASSERT (   cond,
  tag 
)     enum { static_assert_##tag = 1 / (!!(cond)) }

Definition at line 158 of file log.h.

◆ FC_STATIC_STRLEN_ASSERT

#define FC_STATIC_STRLEN_ASSERT (   cond,
  tag 
)

Definition at line 150 of file log.h.

◆ log_base

#define log_base (   level,
  message,
  ... 
)
Value:
do { \
switch (level) { \
case QtFatalMsg: \
qFatal(message, ##__VA_ARGS__); \
break; \
case QtCriticalMsg: \
qCritical(message, ##__VA_ARGS__); \
break; \
case QtWarningMsg: \
qWarning(message, ##__VA_ARGS__); \
break; \
case QtInfoMsg: \
qInfo(message, ##__VA_ARGS__); \
break; \
case QtDebugMsg: \
qDebug(message, ##__VA_ARGS__); \
break; \
} \
} while (false)
struct setting_list * level[OLEVELS_NUM]
Definition: settings.cpp:167

Definition at line 41 of file log.h.

◆ log_debug

#define log_debug (   message,
  ... 
)
Value:
{ \
}

Definition at line 65 of file log.h.

◆ log_packet

#define log_packet   qDebug

Definition at line 72 of file log.h.

◆ log_packet_detailed

#define log_packet_detailed   log_debug

Definition at line 73 of file log.h.

◆ log_test

#define log_test   qInfo

Definition at line 71 of file log.h.

◆ LOG_TEST

#define LOG_TEST   LOG_NORMAL

Definition at line 74 of file log.h.

Function Documentation

◆ fc_assert_are_fatal()

bool fc_assert_are_fatal ( )

Checks whether the fc_assert* macros should raise on failed assertion.

Definition at line 231 of file log.cpp.

Referenced by fc_assert_handle_failure().

◆ fc_assert_handle_failure()

void fc_assert_handle_failure ( const char *  condition,
const char *  file,
int  line,
const char *  function,
const QString &  message = QString() 
)

Handles a failed assertion.

Definition at line 236 of file log.cpp.

◆ fc_assert_set_fatal()

void fc_assert_set_fatal ( bool  fatal_assertions)

Set what signal the assert* macros should raise on failed assertion (-1 to disable).

Definition at line 226 of file log.cpp.

Referenced by client_main(), main(), re_parse_cmdline(), and rup_parse_cmdline().

◆ log_close()

void log_close ( )

Deinitialize logging module.

Definition at line 212 of file log.cpp.

Referenced by client_exit(), con_log_close(), fcmp_deinit(), and main().

◆ log_get_level()

const QString& log_get_level ( )

Retrieves the log level passed to log_init (even if log_init failed).

This can be overridden from the environment, so it's only useful when passing it to the server from the client.

Definition at line 207 of file log.cpp.

Referenced by client_start_server().

◆ log_init()

bool log_init ( const QString &  level_str,
const QStringList &  extra_rules 
)

Parses a log level string as provided by the user on the command line, and installs the corresponding Qt log filters.

Prints a warning and returns false if the log level name isn't known.

Additional logging rules can be passed in Qt format.

Definition at line 55 of file log.cpp.

Referenced by client_main(), fcmp_parse_cmdline(), and main().

◆ log_set_file()

void log_set_file ( const QString &  path)

Redirects the log to a file.

It will still be shown on standard error. This function is not thread-safe.

Definition at line 177 of file log.cpp.

Referenced by client_main(), and con_log_init().

◆ log_time()

void log_time ( const QString &  msg,
bool  log = false 
)

Variable Documentation

◆ LOG_DEBUG

constexpr auto LOG_DEBUG = QtDebugMsg
constexpr

Definition at line 27 of file log.h.

Referenced by adjust_improvement_wants_by_effects(), adv_unit_execute_path(), adv_unit_move(), aiguard_check_charge_unit(), aiguard_check_guard(), auto_arrange_workers(), auto_settler_setup_work(), ba_human_wants(), building_advisor(), building_advisor_choose(), check_tilespec_capabilities(), city_map_update_radius_sq(), contemplate_new_city(), contemplate_terrain_improvements(), dai_airlift(), dai_auto_settler_run(), dai_build_adv_adjust(), dai_build_adv_override(), dai_choose_diplomat_defensive(), dai_choose_help_wonder(), dai_choose_trade_route(), dai_city_choose_build(), dai_diplomacy_actions(), dai_diplomacy_begin_new_phase(), dai_goldequiv_clause(), dai_log_path(), dai_manage_airunit(), dai_manage_barbarian_leader(), dai_manage_government(), dai_manage_military(), dai_manage_tech(), dai_manage_unit(), dai_military_attack(), dai_military_attack_barbarian(), dai_military_bodyguard(), dai_military_defend(), dai_military_findjob(), dai_process_defender_want(), dai_rampage_want(), dai_select_tech(), dai_set_defenders(), dai_unit_bodyguard_move(), dai_unit_goto(), dai_unit_goto_constrained(), dai_unit_move(), dai_unit_new_task(), dai_wants_defender_against(), dai_wants_role_unit(), dai_war_desire(), domestic_advisor_choose_build(), explorer_goto(), find_best_city_placement(), find_best_tile_to_paradrop_to(), find_something_to_kill(), generate_city_map_indices(), kill_something_with(), luascript_callback_invoke(), luascript_common_a_register(), military_advisor_choose_build(), process_attacker_want(), script_fcdb_cmd_reply(), settler_evaluate_improvements(), and want_tech_for_improvement_effect().

◆ LOG_ERROR

◆ LOG_FATAL

◆ LOG_NORMAL

◆ LOG_VERBOSE

◆ LOG_WARN

constexpr auto LOG_WARN = QtWarningMsg
constexpr