summaryrefslogtreecommitdiff
path: root/log.h
diff options
context:
space:
mode:
authorDiego Santa Cruz <Diego.SantaCruz@spinetix.com>2020-09-09 16:16:49 +0000
committerTobias Klauser <tobias.klauser@gmail.com>2020-09-10 11:53:38 +0200
commite496036b592c7c6d1bc419b5683a6a25bf46e193 (patch)
treee944870ae085aa99ce785f9fcfd9c0f6945f8864 /log.h
parenta06a6349436ccddb2909715f495b53fe9a0f8969 (diff)
llmnrd: add command line option to log to syslog instead of stdio
When llmnrd daemonizes stdout and stderr are redirected to /dev/null and all logs are lost. This adds a cli option -s / --syslog to send the logs to syslog instead. Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>
Diffstat (limited to 'log.h')
-rw-r--r--log.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/log.h b/log.h
index 03b77dc..35c2f76 100644
--- a/log.h
+++ b/log.h
@@ -20,12 +20,19 @@
#define LOG_H
#include <stdio.h>
+#include <syslog.h>
-#define log_err(fmt, args...) fprintf(stderr, "Error: " fmt, ##args)
-#define log_warn(fmt, args...) fprintf(stderr, "Warning: " fmt, ##args)
-#define log_info(fmt, args...) fprintf(stdout, fmt, ##args)
+#include "compiler.h"
+
+void log_lvl(int lvl, const char *fmt, ...) __check_format_printf(2, 3);
+
+void log_to_syslog(void);
+
+#define log_err(fmt, args...) log_lvl(LOG_ERR, fmt, ##args)
+#define log_warn(fmt, args...) log_lvl(LOG_WARNING, fmt, ##args)
+#define log_info(fmt, args...) log_lvl(LOG_INFO, fmt, ##args)
#ifdef DEBUG
-# define log_dbg(fmt, args...) fprintf(stdout, fmt, ##args)
+# define log_dbg(fmt, args...) log_lvl(LOG_DEBUG, fmt, ##args)
#else
# define log_dbg(fmt, args...)
#endif