35 const char *where,
const char *
message);
37 const char *where,
const char *msg);
62static int log_num_files = 0;
63static struct log_fileinfo *log_files = NULL;
67 "Fatal",
"Error",
"Warning",
"Normal",
"Verbose",
"Debug", NULL
102 while ((c = strchr(c,
':'))) {
104 first_len = c - level_str;
119 fc_fprintf(stderr,
_(
"Bad log level \"%s\".\n"), level_str);
125 " Use one of the levels Fatal, Error, Warning, Normal, Verbose, Debug") );
128 if (NULL != ret_level) {
133 fc_fprintf(stderr,
_(
"Bad log level %d in \"%s\".\n"),
138 _(
"Freeciv must be compiled with the FREECIV_DEBUG flag "
139 "to use debug level %d.\n"),
max_level + 1);
160 fc_fprintf(stderr,
_(
"Bad log level %c in \"%s\".\n"),
165 fc_fprintf(stderr,
_(
"Badly formed log level argument \"%s\".\n"),
173 log_num_files *
sizeof(
struct log_fileinfo));
176 tok = strtok(dupled,
":");
179 fc_fprintf(stderr,
_(
"Badly formed log level argument \"%s\".\n"),
185 struct log_fileinfo *pfile = log_files + i;
186 char *d = strchr(tok,
',');
190 pfile->level =
level;
195 d = strchr(d + 1,
',');
196 if (d && *pc !=
'\0' && d[1] !=
'\0') {
199 fc_fprintf(stderr,
_(
"Not an unsigned integer: '%s'\n"), pc);
204 fc_fprintf(stderr,
_(
"Not an unsigned integer: '%s'\n"), d + 1);
210 if (strlen(tok) == 0) {
211 fc_fprintf(stderr,
_(
"Empty filename in log level argument \"%s\".\n"),
218 tok = strtok(NULL,
":");
221 if (i != log_num_files) {
222 fc_fprintf(stderr,
_(
"Badly formed log level argument \"%s\".\n"),
233 _(
"Freeciv must be compiled with the FREECIV_DEBUG flag "
234 "to use advanced log levels based on files.\n"));
254 if (filename && strlen(filename) > 0) {
332 if (lvl < LOG_FATAL || lvl >
LOG_DEBUG) {
345 const char *file,
int line)
347 struct log_fileinfo *pfile;
350 for (i = 0, pfile = log_files; i < log_num_files; i++, pfile++) {
351 if (pfile->level >=
level
352 && 0 == strcmp(pfile->name, file)
353 && ((0 == pfile->min && 0 == pfile->max)
354 || (pfile->min <= line && pfile->max >= line))) {
367 const char *where,
const char *
message)
388 if (print_from_where) {
403void vdo_log(
const char *file,
const char *function,
int line,
405 char *buf,
int buflen,
const char *
message, va_list args)
415 fc_snprintf(buf_where,
sizeof(buf_where),
"in %s() [%s::%d]: ",
416 function, file, line);
431 const char *where,
const char *msg)
434 static unsigned int repeated = 0;
435 static unsigned int next = 2;
436 static unsigned int prev = 0;
446 _(
"Couldn't open logfile: %s for appending \"%s\".\n"),
454 if (
level == prev_level && 0 == strncmp(msg, last_msg,
457 if (repeated == next) {
459 PL_(
"last message repeated %d time",
460 "last message repeated %d times",
461 repeated-prev), repeated-prev);
465 PL_(
" (total %d repeat)",
466 " (total %d repeats)",
467 repeated), repeated);
469 log_write(fs, prev_level, print_from_where, where, buf);
474 if (repeated > 0 && repeated != prev) {
477 log_write(fs, prev_level, print_from_where, where, last_msg);
480 PL_(
"last message repeated %d time",
481 "last message repeated %d times",
482 repeated - prev), repeated - prev);
485 PL_(
" (total %d repeat)",
" (total %d repeats)",
486 repeated), repeated);
488 log_write(fs, prev_level, print_from_where, where, buf);
514void do_log(
const char *file,
const char *function,
int line,
536#ifndef FREECIV_NDEBUG
542 const char *assertion,
const char *
message, ...)
546 if (NULL != assertion) {
548 "assertion '%s' failed.", assertion);
564 _(
"Please report this message at %s"), BUG_URL);
void deprecation_pending(const char *format,...)
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
#define PL_(String1, String2, n)
void fc_allocate_mutex(fc_mutex *mutex)
void fc_release_mutex(fc_mutex *mutex)
void fc_destroy_mutex(fc_mutex *mutex)
void fc_init_mutex(fc_mutex *mutex)
void fc_assert_fail(const char *file, const char *function, int line, const char *assertion, const char *message,...)
static log_pre_callback_fn log_pre_callback
static enum log_level max_level
static void log_real(enum log_level level, bool print_from_where, const char *where, const char *msg)
void log_init(const char *filename, enum log_level initial_level, log_callback_fn callback, log_prefix_fn prefix, int fatal_assertions)
static char * log_level_names[]
static char * log_filename
void fc_assert_set_fatal(int fatal_assertions)
static log_callback_fn log_callback
void log_set_level(enum log_level level)
log_callback_fn log_set_callback(log_callback_fn callback)
const char * log_level_name(enum log_level lvl)
static void log_write(FILE *fs, enum log_level level, bool print_from_where, const char *where, const char *message)
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)
static int fc_fatal_assertions
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
log_prefix_fn log_set_prefix(log_prefix_fn prefix)
void do_log(const char *file, const char *function, int line, bool print_from_where, enum log_level level, const char *message,...)
static log_prefix_fn log_prefix
enum log_level log_get_level(void)
static enum log_level fc_log_level
static fc_mutex logfile_mutex
const char *(* log_prefix_fn)(void)
void(* log_callback_fn)(enum log_level, const char *, bool file_too)
#define log_verbose(message,...)
void(* log_pre_callback_fn)(enum log_level, bool print_from_where, const char *where, const char *msg)
#define log_debug(message,...)
#define fc_realloc(ptr, sz)
static int fatal_assertions
struct setting_list * level[OLEVELS_NUM]
bool str_to_uint(const char *str, unsigned int *pint)
int fc_snprintf(char *str, size_t n, const char *format,...)
int cat_snprintf(char *str, size_t n, const char *format,...)
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
FILE * fc_fopen(const char *filename, const char *opentype)
int fc_strncasecmp(const char *str0, const char *str1, size_t n)
#define sz_strlcpy(dest, src)