aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar zfl9 <zfl9.com@gmail.com> 2019-08-30 20:47:00 +0800
committerGravatar zfl9 <zfl9.com@gmail.com> 2019-08-30 20:47:00 +0800
commit523e8f99899a9587e36e74c5ef103cb64f98c807 (patch)
tree82db285260ab951128bff113917c87696c127625
parentInitial commit (diff)
downloaddns2tcp-523e8f99899a9587e36e74c5ef103cb64f98c807.tar.gz
dns2tcp-523e8f99899a9587e36e74c5ef103cb64f98c807.tar.bz2
dns2tcp-523e8f99899a9587e36e74c5ef103cb64f98c807.zip
add logutils.h
-rw-r--r--logutils.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/logutils.h b/logutils.h
new file mode 100644
index 0000000..efc73e2
--- /dev/null
+++ b/logutils.h
@@ -0,0 +1,27 @@
+#ifndef DNS2TCP_LOGUTILS_H
+#define DNS2TCP_LOGUTILS_H
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <time.h>
+#undef _GNU_SOURCE
+
+#define LOGINF(fmt, ...) \
+ do { \
+ struct tm *tm = localtime(&(time_t){time(NULL)}); \
+ printf("\e[1;32m%04d-%02d-%02d %02d:%02d:%02d INF:\e[0m " fmt "\n", \
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, \
+ tm->tm_hour, tm->tm_min, tm->tm_sec, \
+ ##__VA_ARGS__); \
+ } while (0)
+
+#define LOGERR(fmt, ...) \
+ do { \
+ struct tm *tm = localtime(&(time_t){time(NULL)}); \
+ printf("\e[1;35m%04d-%02d-%02d %02d:%02d:%02d ERR:\e[0m " fmt "\n", \
+ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, \
+ tm->tm_hour, tm->tm_min, tm->tm_sec, \
+ ##__VA_ARGS__); \
+ } while (0)
+
+#endif