diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-05-01 15:12:09 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-05-01 15:12:09 +0200 |
commit | 009dc3ba991290de19f0a5e4e4a25a33e82689cc (patch) | |
tree | 8207ae9b3d72525029088d2cef31460f9daa24f0 /src/log.h | |
parent | bd8e73aad283611c096f07e0fc16aa4985f9f2eb (diff) | |
download | dns-009dc3ba991290de19f0a5e4e4a25a33e82689cc.tar.gz |
improved logging
Diffstat (limited to 'src/log.h')
-rw-r--r-- | src/log.h | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -13,15 +13,16 @@ #include <fcntl.h> #include <unistd.h> -#define _LOG_ERROR 1 -#define _LOG_WARNING 2 -#define _LOG_NOTE 3 -#define _LOG_DEBUG 4 +#define _LOG_ERRNO 1 +#define _LOG_ERROR 2 +#define _LOG_WARNING 3 +#define _LOG_NOTE 4 +#define _LOG_DEBUG 5 extern unsigned int log_loglevel; extern int log_fd; -extern const char* log_loglevel_str[5]; +extern const char* log_loglevel_str[6]; #define LOGPRINTF(l,...) {\ if((l) <= log_loglevel){\ @@ -30,8 +31,8 @@ extern const char* log_loglevel_str[5]; 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_ERRNO)\ + printf("%s: ", strerror(errno));\ if((l) == _LOG_DEBUG)\ printf("%s:%d: ", __FILE__, __LINE__);\ printf(__VA_ARGS__);\ @@ -40,6 +41,15 @@ extern const char* log_loglevel_str[5]; }\ } +// DEBUG Wrapper around LOGPRINTF wich is only compiled in in +// _DEBUG mode for performance + +#ifdef _DEBUG +#define DEBUG(...) { LOGPRINTF(_LOG_DEBUG, __VA_ARGS__); } +#else +#define DEBUG(...) { } +#endif + /** * Opens logfile, writes filedes to _fd |