aboutsummaryrefslogtreecommitdiff
path: root/src/log.h
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-29 23:54:01 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2019-11-29 23:54:01 +0100
commit9a8214e0304a1dffe0a321d96d01045cfc34c8e8 (patch)
tree3a92b0f6de06290f6471eb30821faef6ea14bed6 /src/log.h
parent73ede020c76126e81325fcd8d3e186132db21198 (diff)
downloaddns-9a8214e0304a1dffe0a321d96d01045cfc34c8e8.tar.gz
asdf
Diffstat (limited to 'src/log.h')
-rw-r--r--src/log.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/log.h b/src/log.h
new file mode 100644
index 0000000..8b2c881
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,49 @@
+#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;
+int log_fd;
+
+const char* log_loglevel_str[5];
+
+#define LOGPRINTF(l,...) {\
+ if((l) <= log_loglevel){\
+ time_t current = time (NULL);\
+ struct tm *tma = localtime(&current);\
+ 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);\
+ }\
+}
+
+
+/**
+ * Opens logfile, writes filedes to _fd
+ * */
+int log_init_file(char* _file, unsigned int _verbosity);
+
+/**
+ * Configures LOG macros for stdout
+ */
+int log_init_stdout(unsigned int _verbosity);
+
+int log_close();