logging
This commit is contained in:
parent
9e9af0baf3
commit
b3cf1ca33a
@ -10,12 +10,13 @@ C_INCLUDES = \
|
|||||||
-I. \
|
-I. \
|
||||||
-I../cube/User/Inc
|
-I../cube/User/Inc
|
||||||
|
|
||||||
|
VERSION := $(shell git rev-parse --short=8 HEAD)
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = $(C_INCLUDES) -Wall -Werror -std=c99
|
CFLAGS = $(C_INCLUDES) -Wall -Werror -std=c99 -DVERSION=$(VERSION)
|
||||||
LDFLAGS = -lconfig -lcurl
|
LDFLAGS = -lconfig -lcurl
|
||||||
TARGET = sink20169
|
TARGET = sink20169
|
||||||
|
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
ifeq ($(UNAME_S),OpenBSD)
|
ifeq ($(UNAME_S),OpenBSD)
|
||||||
CFLAGS += -I/usr/local/include -DOpenBSD=1
|
CFLAGS += -I/usr/local/include -DOpenBSD=1
|
||||||
|
@ -2,16 +2,51 @@
|
|||||||
|
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <stdarg.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, ...) {
|
void logmsg(int prio, const char* format, ...) {
|
||||||
va_list vl;
|
va_list vl;
|
||||||
|
char buf[1024];
|
||||||
openlog("counter", 0, LOG_LOCAL1);
|
|
||||||
va_start(vl, format);
|
va_start(vl, format);
|
||||||
vsyslog(prio, format, vl);
|
vsnprintf(buf, sizeof(buf), format, vl);
|
||||||
//vprintf(format, vl);
|
|
||||||
va_end(vl);
|
va_end(vl);
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
printf(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
openlog("counter", 0, facility);
|
||||||
|
syslog(prio, buf);
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
void logmsg(int prio, const char* format, ...);
|
void logmsg(int prio, const char* format, ...);
|
||||||
|
void setfacility(const char *facility_p);
|
||||||
#endif // _LOGGING_H_
|
#endif // _LOGGING_H_
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
@ -48,6 +49,8 @@ typedef struct {
|
|||||||
char influxUrl[1024];
|
char influxUrl[1024];
|
||||||
} t_forwarderHandle;
|
} t_forwarderHandle;
|
||||||
|
|
||||||
|
bool verbose = false;
|
||||||
|
|
||||||
|
|
||||||
int initConfig(const char *configFilename, t_configHandle *configHandle) {
|
int initConfig(const char *configFilename, t_configHandle *configHandle) {
|
||||||
configHandle->numOfDevices = 0;
|
configHandle->numOfDevices = 0;
|
||||||
@ -312,11 +315,22 @@ int main(int argc, char **argv) {
|
|||||||
const char *configFilename = DEFAULT_CONFIG_FILENAME;
|
const char *configFilename = DEFAULT_CONFIG_FILENAME;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "f:")) != -1) {
|
while ((c = getopt(argc, argv, "f:vs:")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'f':
|
case 'f':
|
||||||
configFilename = strdup(optarg);
|
configFilename = strdup(optarg);
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user