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.c | |
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.c')
-rw-r--r-- | log.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -0,0 +1,39 @@ +#include <stdarg.h> +#include <stdbool.h> + +#include "log.h" + +static bool use_syslog; + +void log_lvl(int lvl, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + + if (!use_syslog) { + FILE *out = stderr; + switch (lvl) { + case LOG_ERR: + fputs("Error: ", stderr); + break; + case LOG_WARNING: + fputs("Warning: ", stderr); + break; + case LOG_INFO: + case LOG_DEBUG: + out = stdout; + break; + } + vfprintf(out, fmt, ap); + } else { + vsyslog(lvl, fmt, ap); + } + + va_end(ap); +} + +void log_to_syslog(void) +{ + use_syslog = true; +} |