Switch to standard logging framework

This commit is contained in:
Ian Gulliver
2016-03-05 22:54:26 -08:00
parent 06e73e2319
commit 6480a960fa
20 changed files with 102 additions and 67 deletions

30
adsbus/log.c Normal file
View File

@@ -0,0 +1,30 @@
#include <assert.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include "log.h"
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
static FILE *log_stream = NULL;
void log_init() {
log_stream = fdopen(STDERR_FILENO, "a");
assert(log_stream);
setlinebuf(log_stream);
}
void log_cleanup() {
assert(!fclose(log_stream));
}
__attribute__ ((__format__ (__printf__, 3, 4)))
void log_write(char type, const uint8_t *id, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
assert(fprintf(log_stream, "%c %s: ", type, id) > 0);
assert(vfprintf(log_stream, fmt, ap) > 0);
assert(fprintf(log_stream, "\n") == 1);
va_end(ap);
}