1
0
forked from bip/bip

Log without timestamp in specific situations (early/conf phase)

This commit is contained in:
Loïc Gomez 2024-02-04 15:38:47 +09:00
parent 771f664f02
commit b0725acd05
3 changed files with 36 additions and 6 deletions

View File

@ -160,7 +160,7 @@ void conf_die(bip_t *bip, char *fmt, ...)
error = bip_realloc(error, size);
}
va_start(ap, fmt);
_mylog(LOG_ERROR, fmt, ap);
mylog(LOG_ERROR, fmt, ap);
va_end(ap);
}

View File

@ -34,6 +34,7 @@ extern int conf_log_system;
extern int errno;
#pragma GCC diagnostic pop
extern FILE *conf_global_log_file;
void _mylog(int level, int with_timestamp, char *fmt, va_list ap);
void memory_fatal(void)
{
@ -260,7 +261,7 @@ char *checkmode2text(int v)
}
#endif
void _mylog(int level, char *fmt, va_list ap)
void _mylog(int level, int with_timestamp, char *fmt, va_list ap)
{
char *prefix;
@ -294,7 +295,11 @@ void _mylog(int level, char *fmt, va_list ap)
break;
}
fprintf(conf_global_log_file, "%s %s", timestamp(), prefix);
if (with_timestamp)
fprintf(conf_global_log_file, "%s %s", timestamp(), prefix);
else
fprintf(conf_global_log_file, "%s", prefix);
vfprintf(conf_global_log_file, fmt, ap);
fprintf(conf_global_log_file, "\n");
#ifdef DEBUG
@ -307,7 +312,16 @@ void mylog(int level, char *fmt, ...)
va_list ap;
va_start(ap, fmt);
_mylog(level, fmt, ap);
_mylog(level, 1, fmt, ap);
va_end(ap);
}
void mylog_nots(int level, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_mylog(level, 0, fmt, ap);
va_end(ap);
}
@ -330,7 +344,22 @@ void fatal(char *fmt, ...)
va_list ap;
va_start(ap, fmt);
_mylog(LOG_FATAL, fmt, ap);
_mylog(LOG_FATAL, 1, fmt, ap);
va_end(ap);
#ifdef HAVE_BACKTRACE
dump_trace();
#endif
exit(200);
}
void fatal_nots(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_mylog(LOG_FATAL, 0, fmt, ap);
va_end(ap);
#ifdef HAVE_BACKTRACE

View File

@ -32,8 +32,9 @@
#define HASH_DEFAULT 0
void mylog(int level, char *fmt, ...);
void _mylog(int level, char *fmt, va_list ap);
void mylog_nots(int level, char *fmt, ...);
void fatal(char *fmt, ...);
void fatal_nots(char *fmt, ...);
char *timestamp(void);
struct hash_item;