This commit is contained in:
Wolfgang Hottgenroth 2021-02-11 11:28:43 +01:00
parent 9e9af0baf3
commit b3cf1ca33a
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
4 changed files with 59 additions and 9 deletions

View File

@ -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

View File

@ -2,16 +2,51 @@
#include <syslog.h>
#include <stdarg.h>
// #include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
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();
}

View File

@ -4,5 +4,5 @@
#include <syslog.h>
void logmsg(int prio, const char* format, ...);
void setfacility(const char *facility_p);
#endif // _LOGGING_H_

View File

@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
@ -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;
}
}