diff options
author | nirav <nirav@teisuu.com> | 2019-03-10 23:45:19 +0530 |
---|---|---|
committer | Dandelion <nirav@teisuu.com> | 2019-03-11 23:05:22 +0530 |
commit | 63e8c7f9d095fe0b1e0b44f950230c0e238f166d (patch) | |
tree | 01e0211f4fdede1eccda010fc944b3a0180a9632 /src/log.c | |
parent | 7e8ea36eb8106b4847af13a27a3e8f3177d25809 (diff) | |
download | ap_client-63e8c7f9d095fe0b1e0b44f950230c0e238f166d.tar.gz ap_client-63e8c7f9d095fe0b1e0b44f950230c0e238f166d.zip |
Add config and log
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#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); +} + |