fix: better logging behaviour

This commit is contained in:
Tobias Reisinger 2020-07-26 21:00:05 +02:00
parent 3e6d0333b7
commit 398019afe8
36 changed files with 256 additions and 188 deletions

View file

@ -30,21 +30,21 @@ bind_tcp_server(const char *addr, const char *port, int max_client_backlog)
if ((status = getaddrinfo(addr, port, &hints, &res)) != 0)
{
LOG_ERROR("error getting address info: %s\n", gai_strerror(status));
LOGGER_ERR("error getting address info: %s\n", gai_strerror(status));
}
fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if ((status = bind(fd, res->ai_addr, res->ai_addrlen)) == -1)
{
LOG_ERROR("error binding socket: %s\n", status);
LOGGER_ERR("error binding socket: %s\n", status);
freeaddrinfo(res);
return -1;
}
if ((status = listen(fd, max_client_backlog)) == -1)
{
LOG_ERROR("error setting up listener: %s\n", status);
LOGGER_ERR("error setting up listener: %s\n", status);
freeaddrinfo(res);
return -1;
}
@ -78,14 +78,14 @@ send_udp_broadcast(const char *addr, uint16_t port, void *message, size_t length
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
LOG_ERROR("error creating socket\n");
LOGGER_ERR("error creating socket\n");
return -1;
}
int broadcast = 1;
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &broadcast, sizeof broadcast) < 0)
{
LOG_ERROR("error setting broadcast\n");
LOGGER_ERR("error setting broadcast\n");
return -1;
}
@ -96,7 +96,7 @@ send_udp_broadcast(const char *addr, uint16_t port, void *message, size_t length
if(sendto(fd, message, length, 0, (struct sockaddr *)&their_addr, sizeof(their_addr)) < 0)
{
LOG_ERROR("error sending broadcast (%d): '%s'\n", errno, strerror(errno));
LOGGER_ERR("error sending broadcast (%d): '%s'\n", errno, strerror(errno));
return -1;
}
close(fd);
@ -114,7 +114,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
if(discover_server_port == -1)
{
LOG_ERROR("failed to get server port for discovery\n");
LOGGER_ERR("failed to get server port for discovery\n");
static const char content[] = "";
response->status_code = 500;
response->content_type = "text/plain";
@ -129,7 +129,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
if(send_udp_broadcast("255.255.255.255", global_config.discovery_port, payload, sizeof(payload)) < 0)
{
LOG_ERROR("failed to send UDP broadcast\n");
LOGGER_ERR("failed to send UDP broadcast\n");
static const char content[] = "";
response->status_code = 500;
response->content_type = "text/plain";
@ -168,7 +168,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
{
if((client_fd = accept(discover_server_socket, (struct sockaddr *) &their_addr, &addr_size)) < 0)
{
LOG_ERROR("error accepting client %s\n", strerror(errno));
LOGGER_ERR("error accepting client %s\n", strerror(errno));
continue;
}
@ -176,7 +176,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
if(recv(client_fd, &payload_length, sizeof(payload_length), 0) <= 0)
{
LOG_ERROR("error receiving header from client\n");
LOGGER_ERR("error receiving header from client\n");
continue;
}
@ -185,7 +185,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
if((bytes_transferred = recv(client_fd, answer_payload, payload_length, 0)) <= 0)
{
LOG_ERROR("error receiving payload from client\n");
LOGGER_ERR("error receiving payload from client\n");
continue;
}
@ -194,7 +194,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
if(getpeername(client_fd, (struct sockaddr *)&addr, &client_addr_size) != 0)
{
LOG_ERROR("error receiving payload from client\n");
LOGGER_ERR("error receiving payload from client\n");
continue;
}
@ -301,7 +301,7 @@ api_v1_controllers_discover_POST(struct mg_connection *nc, struct http_message *
{
known_controllers[i]->active = false;
controller_save(known_controllers[i]);
LOG_DEBUG("lost: %s\n", known_controllers[i]->name);
LOGGER_DEBUG("lost: %s\n", known_controllers[i]->name);
}
controller_free_list(known_controllers);