diff options
Diffstat (limited to 'src/output.c')
| -rw-r--r-- | src/output.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/output.c b/src/output.c new file mode 100644 index 0000000..daa25f2 --- /dev/null +++ b/src/output.c @@ -0,0 +1,53 @@ +// TODO general logging overhaul. make sure messages make sense, are consistent, etc. +// TODO make this not rely on so many globals. +// TODO colorize stdout for easier reading + +#include <stdarg.h> +#include <stdbool.h> +#include <stdio.h> +#include <syslog.h> + +#include "net.h" + +extern bool quiet; +extern bool daemonize; +extern bool remote_logging; +extern bool use_syslog; +extern bool log_to_file; +extern FILE *outfilep; +extern sock_t sock; + +// output logs according to runtime configuration +void output(const char *msg) { + if (!daemonize) { + if (!quiet) { + printf("%s\n", msg); + } + } + + if (remote_logging) { + sockprintf(sock, "%s\r\n", msg); + } + + if (log_to_file) { + fprintf(outfilep, "%s\n", msg); + } +} + +// Display/log runtime messages +void msg(const char *fmt, ...) { + char buf[8192] = {0}; + va_list vl; + + va_start(vl, fmt); + vsnprintf(buf, sizeof(buf), fmt, vl); + va_end(vl); + + if (use_syslog) { + syslog(LOG_INFO | LOG_USER, "%s", buf); + } + + if (!daemonize) { + printf("%s\n", buf); + } +} |
