Freeciv-3.3
Loading...
Searching...
No Matches
Functions | Variables
log.c File Reference
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "deprecations.h"
#include "fciconv.h"
#include "fcintl.h"
#include "fcthread.h"
#include "mem.h"
#include "shared.h"
#include "support.h"
#include "log.h"

Go to the source code of this file.

Functions

static void log_write (FILE *fs, enum log_level level, bool print_from_where, const char *where, const char *message)
 
static void log_real (enum log_level level, bool print_from_where, const char *where, const char *msg)
 
bool log_parse_level_str (const char *level_str, enum log_level *ret_level)
 
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)
 
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 charlog_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,...)
 
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,...)
 

Variables

static charlog_filename = nullptr
 
static log_pre_callback_fn log_pre_callback = log_real
 
static log_callback_fn log_callback = nullptr
 
static log_prefix_fn log_prefix = nullptr
 
static fc_mutex logfile_mutex
 
static enum log_level max_level = LOG_VERBOSE
 
static enum log_level fc_log_level = LOG_NORMAL
 
static int fc_fatal_assertions = -1
 
static charlog_level_names []
 
const charnologmsg = "nologmsg:%s"
 

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

Unconditionally print a log message. This function is usually protected by do_log_for(). For repeat message, may wait and print instead "last message repeated ..." at some later time. Calls log_callback if not nullptr, else prints to stderr.

Definition at line 514 of file log.c.

Referenced by caravan_parameter_log_real(), fc_assert_fail(), pf_path_print_real(), real_bodyguard_log(), real_city_log(), real_diplo_log(), real_tech_log(), and real_unit_log().

◆ fc_assert_fail()

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

Returns whether the fc_assert* macros should raise a signal on failed assertion.

Definition at line 541 of file log.c.

◆ 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 nullptr. If both are nullptr, print to stderr. If neither is nullptr, 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_real()

static void log_real ( enum log_level  level,
bool  print_from_where,
const char where,
const char msg 
)
static

Really print a log message. For repeat message, may wait and print instead "last message repeated ..." at some later time. Calls log_callback if not nullptr, else prints to stderr.

Definition at line 430 of file log.c.

◆ 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.

◆ log_write()

static void log_write ( FILE fs,
enum log_level  level,
bool  print_from_where,
const char where,
const char message 
)
static

Unconditionally print a simple string. Let the callback do its own level formatting and add a '
' if it wants.

Definition at line 366 of file log.c.

Referenced by log_real().

◆ 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

◆ fc_fatal_assertions

int fc_fatal_assertions = -1
static

Definition at line 53 of file log.c.

Referenced by fc_assert_fail(), fc_assert_set_fatal(), and log_init().

◆ fc_log_level

enum log_level fc_log_level = LOG_NORMAL
static

Definition at line 52 of file log.c.

Referenced by log_get_level(), log_init(), and log_set_level().

◆ log_callback

log_callback_fn log_callback = nullptr
static

Definition at line 41 of file log.c.

Referenced by log_init(), log_set_callback(), and log_write().

◆ log_filename

char* log_filename = nullptr
static

Definition at line 39 of file log.c.

Referenced by con_log_init(), log_init(), log_real(), and log_write().

◆ log_level_names

char* log_level_names[]
static
Initial value:
= {
"Fatal", "Error", "Warning", "Normal", "Verbose", "Debug", nullptr
}

Definition at line 66 of file log.c.

Referenced by log_level_name(), and log_parse_level_str().

◆ log_pre_callback

log_pre_callback_fn log_pre_callback = log_real
static

Definition at line 40 of file log.c.

Referenced by log_set_pre_callback(), and vdo_log().

◆ log_prefix

log_prefix_fn log_prefix = nullptr
static

Definition at line 42 of file log.c.

Referenced by con_log_init(), log_init(), log_set_prefix(), and log_write().

◆ logfile_mutex

fc_mutex logfile_mutex
static

Definition at line 44 of file log.c.

Referenced by log_close(), log_init(), and log_real().

◆ max_level

enum log_level max_level = LOG_VERBOSE
static

Definition at line 49 of file log.c.

Referenced by log_parse_level_str(), and send_server_access_level_settings().

◆ nologmsg

const char* nologmsg = "nologmsg:%s"

Definition at line 72 of file log.c.