diff --git a/sink/Makefile b/sink/Makefile index b3e9feb..6755469 100644 --- a/sink/Makefile +++ b/sink/Makefile @@ -10,12 +10,13 @@ C_INCLUDES = \ -I. \ -I../cube/User/Inc +VERSION := $(shell git rev-parse --short=8 HEAD) + CC = gcc -CFLAGS = $(C_INCLUDES) -Wall -Werror -std=c99 +CFLAGS = $(C_INCLUDES) -Wall -Werror -std=c99 -DVERSION=$(VERSION) LDFLAGS = -lconfig -lcurl TARGET = sink20169 - UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),OpenBSD) CFLAGS += -I/usr/local/include -DOpenBSD=1 diff --git a/sink/logging.c b/sink/logging.c index d8ab01e..81fc67b 100644 --- a/sink/logging.c +++ b/sink/logging.c @@ -2,16 +2,51 @@ #include #include -// #include +#include +#include + +extern bool verbose; +int facility = LOG_LOCAL0; + +void setfacility(const char *facility_p) { + if (! strcmp(facility_p, "LOCAL0")) { + facility = LOG_LOCAL0; + } else if (! strcmp(facility_p, "LOCAL1")) { + facility = LOG_LOCAL1; + } else if (! strcmp(facility_p, "LOCAL2")) { + facility = LOG_LOCAL2; + } else if (! strcmp(facility_p, "LOCAL3")) { + facility = LOG_LOCAL3; + } else if (! strcmp(facility_p, "LOCAL4")) { + facility = LOG_LOCAL4; + } else if (! strcmp(facility_p, "LOCAL5")) { + facility = LOG_LOCAL5; + } else if (! strcmp(facility_p, "LOCAL6")) { + facility = LOG_LOCAL6; + } else if (! strcmp(facility_p, "LOCAL7")) { + facility = LOG_LOCAL7; + } else if (! strcmp(facility_p, "USER")) { + facility = LOG_USER; + } else if (! strcmp(facility_p, "DAEMON")) { + facility = LOG_DAEMON; + } +} + void logmsg(int prio, const char* format, ...) { va_list vl; - - openlog("counter", 0, LOG_LOCAL1); + char buf[1024]; + va_start(vl, format); - vsyslog(prio, format, vl); - //vprintf(format, vl); + vsnprintf(buf, sizeof(buf), format, vl); va_end(vl); + + if (verbose) { + printf(buf); + } + + openlog("counter", 0, facility); + syslog(prio, buf); closelog(); } diff --git a/sink/logging.h b/sink/logging.h index 57bd67f..12d34b2 100644 --- a/sink/logging.h +++ b/sink/logging.h @@ -4,5 +4,5 @@ #include void logmsg(int prio, const char* format, ...); - +void setfacility(const char *facility_p); #endif // _LOGGING_H_ diff --git a/sink/sink20169.c b/sink/sink20169.c index 7851ee1..2050567 100644 --- a/sink/sink20169.c +++ b/sink/sink20169.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -48,6 +49,8 @@ typedef struct { char influxUrl[1024]; } t_forwarderHandle; +bool verbose = false; + int initConfig(const char *configFilename, t_configHandle *configHandle) { configHandle->numOfDevices = 0; @@ -312,11 +315,22 @@ int main(int argc, char **argv) { const char *configFilename = DEFAULT_CONFIG_FILENAME; int c; - while ((c = getopt(argc, argv, "f:")) != -1) { + while ((c = getopt(argc, argv, "f:vs:")) != -1) { switch (c) { case 'f': configFilename = strdup(optarg); break; + case 'v': + verbose = true; + break; + case 's': + setfacility(optarg); + break; + case 'h': + printf("sinkserver for mainsfrequency counter\n"); + printf("https://home.hottis.de/gitlab/wolutator/mains-frequency-counter-stm32\n"); + printf("Version: " VERSION "\n"); + break; } }