diff options
Diffstat (limited to 'log.c')
-rw-r--r-- | log.c | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -0,0 +1,28 @@ +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <syslog.h> +#include "log.h" +#include "misc.h" + +void vprintlog(log_output output_type, int priority, const char *fmt, va_list args) { + char *buf = calloc(vformat_len_copy(fmt, args)+1, sizeof(char)); + vsprintf(buf, fmt, args); + + switch (output_type) { + case LOG_OUT_SYSLOG: { + syslog(priority, "%s", buf); + break; + } + case LOG_OUT_STDERR: + case LOG_OUT_STDOUT: { + FILE *output = (output_type == LOG_OUT_STDOUT) ? stdout : stderr; + fprintf(output, "%s\n", buf); + break; + } + default: + break; + } + free(buf); +} |