=================================================================== RCS file: /cvs/cvs/blind/log.c,v retrieving revision 1.1 retrieving revision 1.4 diff -u -p -r1.1 -r1.4 --- blind/log.c 2022/03/17 09:09:26 1.1 +++ blind/log.c 2022/03/18 09:20:46 1.4 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Daniel Kroczynski +1;95;0c * Copyright (c) 2022 Daniel Kroczynski * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -14,16 +14,20 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include #include +static int log_background; static int log_verbose; const char *log_procname; void log_init(int, int); void log_setv(int); int log_getv(void); +void log_send(const char *, va_list) + __attribute__((__format__ (printf, 1, 0))); void log_info(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_debug(const char *, ...) @@ -37,7 +41,8 @@ log_init(int background, int facility) if (__progname != NULL) log_procname = __progname; - if (background) + log_background = background; + if (log_background) openlog(log_procname, LOG_PID | LOG_NDELAY, facility); tzset(); @@ -56,12 +61,23 @@ log_getv(void) } void +log_send(const char *info, va_list ap) +{ + if (log_background) + vsyslog(LOG_INFO, info, ap); + else { + vfprintf(stderr, info, ap); + fprintf(stderr, "\n"); + } +} + +void log_info(const char *info, ...) { va_list ap; va_start(ap, info); - vsyslog(LOG_INFO, info, ap); + log_send(info, ap); va_end(ap); } @@ -72,7 +88,7 @@ log_debug(const char *info, ...) if (log_verbose) { va_start(ap, info); - vsyslog(LOG_INFO, info, ap); + log_send(info, ap); va_end(ap); } }