diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2019-09-17 12:26:54 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2019-09-17 12:26:54 +0200 |
commit | 57cb704e6387fd1a84bb26e7242d49a1c268fb40 (patch) | |
tree | 140833a6cebb09cf5161e51f688fb88132c3ce1b /src/log.h | |
parent | 78771b749e406ba14e3014e66b4848ab1f897563 (diff) | |
download | bbs-57cb704e6387fd1a84bb26e7242d49a1c268fb40.tar.gz |
Added logging, fixed in unterminated buffers
Diffstat (limited to 'src/log.h')
-rw-r--r-- | src/log.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/log.h b/src/log.h new file mode 100644 index 0000000..4e48dad --- /dev/null +++ b/src/log.h @@ -0,0 +1,48 @@ +#pragma once + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <time.h> +#include <fcntl.h> +#include <unistd.h> + +#define _LOG_ERROR 1 +#define _LOG_WARNING 2 +#define _LOG_NOTE 3 +#define _LOG_DEBUG 4 + +unsigned int log_loglevel; + +const char* log_loglevel_str[5]; + +#define LOGPRINTF(l,...) {\ + if((l) <= log_loglevel){\ + time_t current = time (NULL);\ + struct tm *tma = localtime(¤t);\ + char* date = asctime(tma);\ + date[strlen(date) - 1] = '\0';\ + printf("[%s] %s: ", date, log_loglevel_str[(l)]);\ + if((l) == _LOG_ERROR)\ + printf("%s:", strerror(errno));\ + if((l) == _LOG_DEBUG)\ + printf("%s:%d: ", __FILE__, __LINE__);\ + printf(__VA_ARGS__);\ + printf("\n");\ + fsync(STDOUT_FILENO);\ + }\ +} + + +int log_init_file(char* _file, unsigned int _verbosity); +/** + * Opens logfile, writes filedes to _fd + * */ + +int log_init_stdout(unsigned int _verbosity); +/** + * Configures LOG macros for stdout + */ + + |