fix: logger
This commit is contained in:
parent
61e025343d
commit
db3bcaf7d1
28 changed files with 200 additions and 180 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <logger.h>
|
||||
|
@ -25,7 +26,7 @@ helper_bind_tcp_server(char* addr, uint16_t port, int max_client_backlog)
|
|||
|
||||
if ((status = getaddrinfo(addr, port_str, &hints, &res)) != 0)
|
||||
{
|
||||
LOG_ERROR("getaddrinfo: %s", gai_strerror(status));
|
||||
LOG_ERROR("getaddrinfo: %s\n", gai_strerror(status));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -33,14 +34,14 @@ helper_bind_tcp_server(char* addr, uint16_t port, int max_client_backlog)
|
|||
|
||||
if ((status = bind(fd, res->ai_addr, res->ai_addrlen)) == -1)
|
||||
{
|
||||
LOG_ERROR("error binding socket: %s", strerror(errno));
|
||||
LOG_ERROR("error binding socket: %s\n", strerror(errno));
|
||||
freeaddrinfo(res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((status = listen(fd, max_client_backlog)) == -1)
|
||||
{
|
||||
LOG_ERROR("error setting up listener: %s", strerror(errno));
|
||||
LOG_ERROR("error setting up listener: %s\n", strerror(errno));
|
||||
freeaddrinfo(res);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ helper_connect_tcp_server(char* host, uint16_t port)
|
|||
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); //creating Socket
|
||||
|
||||
if ((status = connect(s, res->ai_addr, res->ai_addrlen)) != 0) {
|
||||
LOG_ERROR("connect() failed");
|
||||
LOG_ERROR("connect() failed\n");
|
||||
freeaddrinfo(res);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ helper_get_port(int sock)
|
|||
socklen_t len = sizeof(sin);
|
||||
if (getsockname(sock, (struct sockaddr *)&sin, &len) == -1)
|
||||
{
|
||||
LOG_ERROR("could not get socket name for port: %s", strerror(errno));
|
||||
LOG_ERROR("could not get socket name for port: %s\n", strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -30,6 +30,41 @@ helper_load_config(IniDispatch *disp, void *config_void)
|
|||
strcpy(config->database, disp->value);
|
||||
return 0;
|
||||
}
|
||||
if(CONFINI_IS_KEY("controller", "log-level"))
|
||||
{
|
||||
if(strcasecmp(disp->value, "trace") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_TRACE;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "debug") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_DEBUG;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "info") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_INFO;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "warn") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_WARN;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "error") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_ERROR;
|
||||
return 0;
|
||||
}
|
||||
if(strcasecmp(disp->value, "fatal") == 0)
|
||||
{
|
||||
config->log_level = LOG_LEVEL_FATAL;
|
||||
return 0;
|
||||
}
|
||||
LOG_WARN("invalid log-level '%s'\n", disp->value);
|
||||
return 0;
|
||||
}
|
||||
if(CONFINI_IS_KEY("controller", "discovery-port"))
|
||||
{
|
||||
config->discovery_port = atoi(disp->value);
|
||||
|
@ -43,7 +78,7 @@ helper_load_config(IniDispatch *disp, void *config_void)
|
|||
{
|
||||
config->relay_configs[i].driver= RELAY_DRIVER_NONE;
|
||||
}
|
||||
LOG_TRACE("config relay-count set to %u", config->relay_count);
|
||||
LOG_TRACE("config relay-count set to %u\n", config->relay_count);
|
||||
return 0;
|
||||
}
|
||||
for(uint8_t i = 0; i < config->relay_count; ++i)
|
||||
|
@ -71,7 +106,7 @@ helper_load_config(IniDispatch *disp, void *config_void)
|
|||
config->relay_configs[i].driver = RELAY_DRIVER_PIFACE;
|
||||
return 0;
|
||||
}
|
||||
LOG_WARN("invalid driver '%s' in section '%s'", disp->value, relay_section_name);
|
||||
LOG_WARN("invalid driver '%s' in section '%s'\n", disp->value, relay_section_name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ helper_open_discovery_socket(uint16_t discovery_port)
|
|||
//get connection info for our computer
|
||||
if ((status = getaddrinfo(NULL, discovery_port_str, &hints, &res)) != 0)
|
||||
{
|
||||
LOG_FATAL("getaddrinfo: %s", gai_strerror(status));
|
||||
LOG_FATAL("getaddrinfo: %s\n", gai_strerror(status));
|
||||
freeaddrinfo(res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -37,21 +37,21 @@ helper_open_discovery_socket(uint16_t discovery_port)
|
|||
// lose the pesky "Address already in use" error message
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1)
|
||||
{
|
||||
LOG_FATAL("setsockopt: %s", strerror(errno));
|
||||
LOG_FATAL("setsockopt: %s\n", strerror(errno));
|
||||
freeaddrinfo(res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (bind(fd, res->ai_addr, res->ai_addrlen) == -1)
|
||||
{
|
||||
LOG_FATAL("bind: %s", strerror(errno));
|
||||
LOG_FATAL("bind: %s\n", strerror(errno));
|
||||
freeaddrinfo(res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
|
||||
LOG_INFO("opened discovery socket on port %u", discovery_port);
|
||||
LOG_INFO("opened discovery socket on port %u\n", discovery_port);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
|
|
@ -50,12 +50,12 @@ helpers_parse_cli(int argc, const char **argv, config_t *config)
|
|||
config->run_type = RUN_TYPE_TEST;
|
||||
return;
|
||||
}
|
||||
LOG_FATAL("bad action '%s' given ('start', 'test')", argv[0]);
|
||||
LOG_FATAL("bad action '%s' given ('start', 'test')\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_FATAL("no action given ('start', 'test')");
|
||||
LOG_FATAL("no action given ('start', 'test')\n");
|
||||
exit(1);
|
||||
}
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue