From 63e8c7f9d095fe0b1e0b44f950230c0e238f166d Mon Sep 17 00:00:00 2001 From: nirav Date: Sun, 10 Mar 2019 23:45:19 +0530 Subject: Add config and log --- src/log.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/log.c (limited to 'src/log.c') diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..52d7028 --- /dev/null +++ b/src/log.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include "log.h" + +static const char *log_levels[] = { + "info" + "warning", + "error", + "fatal", +}; + +void log_msg(enum log_level level, const char *namespace, const char *format, ...) { + va_list args; + va_start(args, format); + + fprintf(stderr, "%s: %s: ", log_levels[level], namespace); + vfprintf(stderr, format, args); + fprintf(stderr, "\n"); + + if (level == LOG_ERROR) { + exit(EXIT_FAILURE); + } else if (level == LOG_FATAL) { + abort(); + } + + va_end(args); +} + -- cgit v1.2.3