From 2278df1493e064c197913e49b5d1935942d83448 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 6 May 2025 16:57:32 -0700 Subject: initial import --- src/output.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/output.c (limited to 'src/output.c') 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 +#include +#include +#include + +#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); + } +} -- cgit v1.2.3