debug() and log() use the new printf. Feel free to use new formatting

sequences for all output.
This commit is contained in:
Martin Mares 1998-06-17 14:33:29 +00:00
parent ecacdfa434
commit 9556f22585

View file

@ -12,6 +12,7 @@
#include <sys/time.h> #include <sys/time.h>
#include "nest/bird.h" #include "nest/bird.h"
#include "lib/string.h"
static int log_inited; static int log_inited;
static FILE *logf = NULL; static FILE *logf = NULL;
@ -41,6 +42,28 @@ static char *class_names[] = {
"FATAL" "FATAL"
}; };
/* FIXME: Use better buffering */
static void
bvfprintf(FILE *f, char *fmt, va_list args)
{
char buf[4096];
int n;
n = bvsprintf(buf, fmt, args);
fwrite(buf, n, sizeof(char), f);
}
static void
bfprintf(FILE *f, char *fmt, ...)
{
va_list args;
va_start(args, fmt);
bvfprintf(f, fmt, args);
va_end(args);
}
static void static void
vlog(int class, char *msg, va_list args) vlog(int class, char *msg, va_list args)
{ {
@ -49,7 +72,7 @@ vlog(int class, char *msg, va_list args)
time_t now = time(NULL); time_t now = time(NULL);
struct tm *tm = localtime(&now); struct tm *tm = localtime(&now);
fprintf(logf, "%02d-%02d-%04d %02d:%02d:%02d <%s> ", bfprintf(logf, "%02d-%02d-%04d %02d:%02d:%02d <%s> ",
tm->tm_mday, tm->tm_mday,
tm->tm_mon+1, tm->tm_mon+1,
tm->tm_year+1900, tm->tm_year+1900,
@ -57,7 +80,7 @@ vlog(int class, char *msg, va_list args)
tm->tm_min, tm->tm_min,
tm->tm_sec, tm->tm_sec,
class_names[class]); class_names[class]);
vfprintf(logf, msg, args); bvfprintf(logf, msg, args);
fputc('\n', logf); fputc('\n', logf);
fflush(logf); fflush(logf);
} }
@ -68,7 +91,7 @@ vlog(int class, char *msg, va_list args)
else else
{ {
fputs("bird: ", stderr); fputs("bird: ", stderr);
vfprintf(stderr, msg, args); bvfprintf(stderr, msg, args);
fputc('\n', stderr); fputc('\n', stderr);
fflush(stderr); fflush(stderr);
} }
@ -104,7 +127,7 @@ debug(char *msg, ...)
va_start(args, msg); va_start(args, msg);
if (dbgf) if (dbgf)
vfprintf(dbgf, msg, args); bvfprintf(dbgf, msg, args);
va_end(args); va_end(args);
} }