Freeciv-3.2: /fast/freeciv/nightly/S3_2/utility/log.h File Reference

Freeciv-3.2

Loading...
Searching...
No Matches
Macros | Typedefs | Enumerations | Functions | Variables
log.h File Reference
`#include <stdarg.h>`
`#include <stdlib.h>`
`#include "support.h"`

Go to the source code of this file.

## Macros

#define | MAX_LEN_LOG_LINE 5120
#define | __FC_LINE__ __LINE__
#define | NOLOGMSG nologmsg
#define | log_do_output_for_level(level) (log_get_level() >= level)
#define | log_base(level, message, ...)
#define | log_fatal(message, ...)
#define | log_error(message, ...) log_base(LOG_ERROR, message, ## __VA_ARGS__)
#define | log_warn(message, ...) log_base(LOG_WARN, message, ## __VA_ARGS__)
#define | log_normal(message, ...) log_base(LOG_NORMAL, message, ## __VA_ARGS__)
#define | log_verbose(message, ...) log_base(LOG_VERBOSE, message, ## __VA_ARGS__)
#define | log_debug(message, ...) /* Do nothing. */
#define | log_testmatic(message, ...) /* Do nothing. */
#define | log_testmatic_alt(altlvl, message, ...) log_base(altlvl, message, ## __VA_ARGS__)
#define | log_va_list(level, msg, args)
#define | log_test log_normal
#define | log_packet log_verbose
#define | log_packet_detailed log_debug
#define | LOG_TEST LOG_NORMAL /* needed by citylog_*() functions */
#define | fc_assert_full(file, function, line, condition, action, message, ...)
#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)) }

## Typedefs

typedef void(* | log_pre_callback_fn) (enum log_level, bool print_from_where, const char *where, const char *msg)
typedef void(* | log_callback_fn) (enum log_level, const char *, bool file_too)
typedef const char *(* | log_prefix_fn) (void)

## Enumerations

enum | log_level { LOG_FATAL = 0 , LOG_ERROR , LOG_WARN , LOG_NORMAL , LOG_VERBOSE , LOG_DEBUG }

## Functions

void | log_init (const char *filename, enum log_level initial_level, log_callback_fn callback, log_prefix_fn prefix, int fatal_assertions)
void | log_close (void)
bool | log_parse_level_str (const char *level_str, enum log_level *ret_level)
log_pre_callback_fn | log_set_pre_callback (log_pre_callback_fn precallback)
log_callback_fn | log_set_callback (log_callback_fn callback)
log_prefix_fn | log_set_prefix (log_prefix_fn prefix)
void | log_set_level (enum log_level level)
enum log_level | log_get_level (void)
const char * | log_level_name (enum log_level lvl)
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)
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 | fc_assert_set_fatal (int fatal_assertions)
void | fc_assert_fail (const char *file, const char *function, int line, const char *assertion, const char *message,...) fc__attribute((__format__(__printf__

## Variables

const char * | nologmsg

## Macro Definition Documentation

## ◆ __FC_LINE__

#define __FC_LINE__ __LINE__

Definition at line 40 of file log.h.

## ◆ fc_assert

#define fc_assert | ( |  | condition | ) |

Value:
((condition) ? (void) 0 \
: fc_assert_fail(__FILE__, __FUNCTION__, __FC_LINE__, #condition, \
NOLOGMSG, NOLOGMSG))
incite_cost
char * incite_cost
Definition comments.c:74
fc_assert_fail
void fc_assert_fail(const char *file, const char *function, int line, const char *assertion, const char *message,...) fc__attribute((__format__(__printf__
__FC_LINE__
#define __FC_LINE__
Definition log.h:40
NOLOGMSG
#define NOLOGMSG
Definition log.h:44

Definition at line 176 of file log.h.

## ◆ fc_assert_action

#define fc_assert_action | ( |  | condition,
|  |  | action
| ) |  |

Value:
fc_assert_full(__FILE__, __FUNCTION__, __FC_LINE__, condition, action, \
NOLOGMSG, NOLOGMSG)
fc_assert_full
#define fc_assert_full(file, function, line, condition, action, message,...)
Definition log.h:153
action
Definition actions.h:360

Definition at line 187 of file log.h.

## ◆ fc_assert_action_msg

#define fc_assert_action_msg | ( |  | condition,
|  |  | action,
|  |  | message,
|  |  | ...
| ) |  |

Value:
fc_assert_full(__FILE__, __FUNCTION__, __FC_LINE__, condition, action, \
message, ## __VA_ARGS__)
message
Definition messagewin_common.h:29

Definition at line 201 of file log.h.

## ◆ fc_assert_exit

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

Definition at line 197 of file log.h.

## ◆ fc_assert_exit_msg

#define fc_assert_exit_msg | ( |  | condition,
|  |  | message,
|  |  | ...
| ) |  |

Value:
fc_assert_action(condition, \
log_fatal(message, ## __VA_ARGS__); exit(EXIT_FAILURE))
log_fatal
#define log_fatal(message,...)
Definition log.h:100
fc_assert_action
#define fc_assert_action(condition, action)
Definition log.h:187

Definition at line 211 of file log.h.

## ◆ fc_assert_full

#define fc_assert_full | ( |  | file,
|  |  | function,
|  |  | line,
|  |  | condition,
|  |  | action,
|  |  | message,
|  |  | ...
| ) |  |

Value:
if (!(condition)) { \
fc_assert_fail(file, function, line, #condition, \
message, ## __VA_ARGS__); \
action; \
} \
(void) 0 /* Force the usage of ';' at the end of the call. */

Definition at line 153 of file log.h.

## ◆ fc_assert_msg

#define fc_assert_msg | ( |  | condition,
|  |  | message,
|  |  | ...
| ) |  |

Value:
((condition) ? (void) 0 \
: fc_assert_fail(__FILE__, __FUNCTION__, __FC_LINE__, \
#condition, message, ## __VA_ARGS__))

Definition at line 181 of file log.h.

## ◆ fc_assert_ret

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

Definition at line 191 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 205 of file log.h.

## ◆ fc_assert_ret_val

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

Definition at line 194 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 208 of file log.h.

## ◆ FC_STATIC_ASSERT

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

Definition at line 235 of file log.h.

## ◆ FC_STATIC_STRLEN_ASSERT

#define FC_STATIC_STRLEN_ASSERT | ( |  | cond,
|  |  | tag
| ) |  |

Definition at line 227 of file log.h.

## ◆ log_base

#define log_base | ( |  | level,
|  |  | message,
|  |  | ...
| ) |  |

Value:
if (log_do_output_for_level(level)) { \
do_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, \
level, message, ## __VA_ARGS__); \
}
log_do_output_for_level
#define log_do_output_for_level(level)
Definition log.h:89
level
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
FALSE
#define FALSE
Definition support.h:47

Definition at line 94 of file log.h.

## ◆ log_debug

#define log_debug | ( |  | message,
|  |  | ...
| ) |  | /* Do nothing. */

Definition at line 115 of file log.h.

## ◆ log_do_output_for_level

#define log_do_output_for_level | ( |  | level | ) | (log_get_level() >= level)

Definition at line 89 of file log.h.

## ◆ log_error

#define log_error | ( |  | message,
|  |  | ...
| ) |  | log_base(LOG_ERROR, message, ## __VA_ARGS__)

Definition at line 103 of file log.h.

## ◆ log_fatal

#define log_fatal | ( |  | message,
|  |  | ...
| ) |  |

Value:
do_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, \
LOG_FATAL, message, ## __VA_ARGS__);
do_log
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__
LOG_FATAL
@ LOG_FATAL
Definition log.h:29

Definition at line 100 of file log.h.

## ◆ log_normal

#define log_normal | ( |  | message,
|  |  | ...
| ) |  | log_base(LOG_NORMAL, message, ## __VA_ARGS__)

Definition at line 107 of file log.h.

## ◆ log_packet

#define log_packet log_verbose

Definition at line 137 of file log.h.

## ◆ log_packet_detailed

#define log_packet_detailed log_debug

Definition at line 138 of file log.h.

## ◆ log_test

#define log_test log_normal

Definition at line 136 of file log.h.

## ◆ LOG_TEST

#define LOG_TEST LOG_NORMAL /* needed by citylog_*() functions */

Definition at line 139 of file log.h.

## ◆ log_testmatic

#define log_testmatic | ( |  | message,
|  |  | ...
| ) |  | /* Do nothing. */

Definition at line 123 of file log.h.

## ◆ log_testmatic_alt

#define log_testmatic_alt | ( |  | altlvl,
|  |  | message,
|  |  | ...
| ) |  | log_base(altlvl, message, ## __VA_ARGS__)

Definition at line 124 of file log.h.

## ◆ log_va_list

#define log_va_list | ( |  | level,
|  |  | msg,
|  |  | args
| ) |  |

Value:
if (log_do_output_for_level(level)) { \
char __buf_[1024]; \
vdo_log(__FILE__, __FUNCTION__, __FC_LINE__, FALSE, \
level, __buf_, sizeof(__buf_), msg, args); \
}

Definition at line 128 of file log.h.

## ◆ log_verbose

#define log_verbose | ( |  | message,
|  |  | ...
| ) |  | log_base(LOG_VERBOSE, message, ## __VA_ARGS__)

Definition at line 109 of file log.h.

## ◆ log_warn

#define log_warn | ( |  | message,
|  |  | ...
| ) |  | log_base(LOG_WARN, message, ## __VA_ARGS__)

Definition at line 105 of file log.h.

## ◆ MAX_LEN_LOG_LINE

#define MAX_LEN_LOG_LINE 5120

Definition at line 26 of file log.h.

## ◆ NOLOGMSG

#define NOLOGMSG nologmsg

Definition at line 44 of file log.h.

## Typedef Documentation

## ◆ log_callback_fn

typedef void(* log_callback_fn) (enum log_level, const char *, bool file_too)

Definition at line 54 of file log.h.

## ◆ log_pre_callback_fn

typedef void(* log_pre_callback_fn) (enum log_level, bool print_from_where, const char *where, const char *msg)

Definition at line 47 of file log.h.

## ◆ log_prefix_fn

typedef const char *(* log_prefix_fn) (void)

Definition at line 58 of file log.h.

## Enumeration Type Documentation

## ◆ log_level

enum log_level

Enumerator
LOG_FATAL |
LOG_ERROR |
LOG_WARN |
LOG_NORMAL |
LOG_VERBOSE |
LOG_DEBUG |

Definition at line 28 of file log.h.

## Function Documentation

## ◆ do_log()

void do_log | ( | const char * | file,
|  | const char * | function,
|  | int | line,
|  | bool | print_from_where,
|  | enum log_level | level,
|  | const char * | message,
|  |  | ...
| ) |  |

## ◆ fc_assert_fail()

void fc_assert_fail | ( | const char * | file,
|  | const char * | function,
|  | int | line,
|  | const char * | assertion,
|  | const char * | message,
|  |  | ...
| ) |  |

## ◆ fc_assert_set_fatal()

void fc_assert_set_fatal | ( | int | fatal_assertions | ) |

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

Definition at line 531 of file log.c.

## ◆ log_close()

void log_close | ( | void |  | ) |

Deinitialize logging module.

Definition at line 270 of file log.c.

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

## ◆ log_get_level()

enum log_level log_get_level | ( | void |  | ) |

Returns the current log level.

Definition at line 322 of file log.c.

Referenced by client_start_server().

## ◆ log_init()

void log_init | ( | const char * | filename,
|  | enum log_level | initial_level,
|  | log_callback_fn | callback,
|  | log_prefix_fn | prefix,
|  | int | fatal_assertions
| ) |  |

Initialise the log module. Either 'filename' or 'callback' may be NULL. If both are NULL, print to stderr. If both are non-NULL, both callback, and fprintf to file. Pass -1 for fatal_assertions to don't raise any signal on failed assertion.

Definition at line 245 of file log.c.

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

## ◆ log_level_name()

const char * log_level_name | ( | enum log_level | lvl | ) |

Return name of the given log level

Definition at line 330 of file log.c.

Referenced by client_start_server().

## ◆ log_parse_level_str()

bool log_parse_level_str | ( | const char * | level_str,
|  | enum log_level * | ret_level
| ) |  |

level_str should be either "0", "1", "2", "3", "4" or "4:filename" or "4:file1:file2" or "4:filename,100,200" etc

If everything goes ok, returns TRUE. If there was a parsing problem, prints to stderr, and returns FALSE.

Return in ret_level the requested level only if level_str is a simple number (like "0", "1", "2").

Also sets up the log_files data structure. Does not set fc_log_level.

Definition at line 86 of file log.c.

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

## ◆ log_set_callback()

log_callback_fn log_set_callback | ( | log_callback_fn | callback | ) |

Adjust the callback function after initial log_init().

Definition at line 290 of file log.c.

Referenced by ui_init().

## ◆ log_set_level()

void log_set_level | ( | enum log_level | level | ) |

Adjust the logging level after initial log_init().

Definition at line 314 of file log.c.

## ◆ log_set_pre_callback()

log_pre_callback_fn log_set_pre_callback | ( | log_pre_callback_fn | precallback | ) |

Adjust the log preparation callback function.

Definition at line 278 of file log.c.

Referenced by backtrace_deinit(), and backtrace_init().

## ◆ log_set_prefix()

log_prefix_fn log_set_prefix | ( | log_prefix_fn | prefix | ) |

Adjust the prefix callback function after initial log_init().

Definition at line 302 of file log.c.

## ◆ vdo_log()

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
| ) |  |

Unconditionally print a log message. This function is usually protected by do_log_for().

Definition at line 403 of file log.c.

Referenced by bugreport_request(), do_log(), do_log_deprecation(), fc_assert_fail(), and ruleset_error_real().

## Variable Documentation

## ◆ nologmsg

const char* nologmsg

extern

Definition at line 72 of file log.c.