diff options
author | Diego Santa Cruz <Diego.SantaCruz@spinetix.com> | 2020-09-09 16:16:49 +0000 |
---|---|---|
committer | Tobias Klauser <tobias.klauser@gmail.com> | 2020-09-10 11:53:38 +0200 |
commit | e496036b592c7c6d1bc419b5683a6a25bf46e193 (patch) | |
tree | e944870ae085aa99ce785f9fcfd9c0f6945f8864 /log.h | |
parent | a06a6349436ccddb2909715f495b53fe9a0f8969 (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.h | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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 |