summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1998-06-17 16:33:29 +0200
committerMartin Mares <mj@ucw.cz>1998-06-17 16:33:29 +0200
commit9556f225853748d5fee9a21e179b8fd5da2d3c42 (patch)
treeee7a3f103a8e105ad060eaa9b4b3e06f6bf770c0
parentecacdfa434acf8af38ed8c1c0c8e71dab400b0f4 (diff)
downloadbird-9556f225853748d5fee9a21e179b8fd5da2d3c42.tar
bird-9556f225853748d5fee9a21e179b8fd5da2d3c42.zip
debug() and log() use the new printf. Feel free to use new formatting
sequences for all output.
-rw-r--r--sysdep/unix/log.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 8d9facf..b9077c7 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -12,6 +12,7 @@
#include <sys/time.h>
#include "nest/bird.h"
+#include "lib/string.h"
static int log_inited;
static FILE *logf = NULL;
@@ -41,6 +42,28 @@ static char *class_names[] = {
"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
vlog(int class, char *msg, va_list args)
{
@@ -49,15 +72,15 @@ vlog(int class, char *msg, va_list args)
time_t now = time(NULL);
struct tm *tm = localtime(&now);
- fprintf(logf, "%02d-%02d-%04d %02d:%02d:%02d <%s> ",
- tm->tm_mday,
- tm->tm_mon+1,
- tm->tm_year+1900,
- tm->tm_hour,
- tm->tm_min,
- tm->tm_sec,
- class_names[class]);
- vfprintf(logf, msg, args);
+ bfprintf(logf, "%02d-%02d-%04d %02d:%02d:%02d <%s> ",
+ tm->tm_mday,
+ tm->tm_mon+1,
+ tm->tm_year+1900,
+ tm->tm_hour,
+ tm->tm_min,
+ tm->tm_sec,
+ class_names[class]);
+ bvfprintf(logf, msg, args);
fputc('\n', logf);
fflush(logf);
}
@@ -68,7 +91,7 @@ vlog(int class, char *msg, va_list args)
else
{
fputs("bird: ", stderr);
- vfprintf(stderr, msg, args);
+ bvfprintf(stderr, msg, args);
fputc('\n', stderr);
fflush(stderr);
}
@@ -104,7 +127,7 @@ debug(char *msg, ...)
va_start(args, msg);
if (dbgf)
- vfprintf(dbgf, msg, args);
+ bvfprintf(dbgf, msg, args);
va_end(args);
}