fix: better logging behaviour
This commit is contained in:
parent
011c5a6102
commit
0530a350df
30 changed files with 343 additions and 176 deletions
|
|
@ -93,7 +93,7 @@ handler_command(struct mg_connection *c, int ev, void *ev_data)
|
|||
return;
|
||||
}
|
||||
uint32_t payload_length = *((uint32_t*)c->recv_mbuf.buf);
|
||||
LOG_DEBUG("payload_length %d\n", payload_length);
|
||||
LOGGER_DEBUG("payload_length %d\n", payload_length);
|
||||
|
||||
if(c->recv_mbuf.len < payload_length + sizeof(payload_length))
|
||||
{
|
||||
|
|
@ -109,7 +109,7 @@ handler_command(struct mg_connection *c, int ev, void *ev_data)
|
|||
|
||||
uint8_t command_code = mpack_node_u8(mpack_node_map_uint(root, COMMAND_MAPPING_CODE));
|
||||
|
||||
LOG_INFO("received command %d\n", command_code);
|
||||
LOGGER_INFO("received command %d\n", command_code);
|
||||
|
||||
switch(command_code)
|
||||
{
|
||||
|
|
@ -136,12 +136,12 @@ handler_command(struct mg_connection *c, int ev, void *ev_data)
|
|||
handler_command_pulse(root, global_controller);
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("received invalid command\n");
|
||||
LOGGER_ERR("received invalid command\n");
|
||||
}
|
||||
|
||||
if(mpack_tree_destroy(&tree) != mpack_ok)
|
||||
{
|
||||
LOG_WARN("error when destroying mpack tree\n");
|
||||
LOGGER_WARNING("error when destroying mpack tree\n");
|
||||
}
|
||||
controller_save(global_controller, global_mdb_env);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,16 +29,16 @@ handler_discovery(struct mg_connection *c, int ev, void *ev_data)
|
|||
|
||||
if(c->recv_mbuf.len != sizeof(discovery_answer_port))
|
||||
{
|
||||
LOG_ERROR("received invalid discovery from %s\n", ip_buf);
|
||||
LOGGER_ERR("received invalid discovery from %s\n", ip_buf);
|
||||
return;
|
||||
}
|
||||
discovery_answer_port = *((uint16_t*)c->recv_mbuf.buf);
|
||||
|
||||
LOG_INFO("received discovery from %s:%d\n", ip_buf, discovery_answer_port);
|
||||
LOGGER_INFO("received discovery from %s:%d\n", ip_buf, discovery_answer_port);
|
||||
|
||||
if(discovery_answer_port == 0)
|
||||
{
|
||||
LOG_ERROR("invalid port received\n");
|
||||
LOGGER_ERR("invalid port received\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ handler_discovery(struct mg_connection *c, int ev, void *ev_data)
|
|||
// finish writing
|
||||
if(mpack_writer_destroy(&writer) != mpack_ok)
|
||||
{
|
||||
LOG_ERROR("error writing discovery answer payload\n");
|
||||
LOGGER_ERR("error writing discovery answer payload\n");
|
||||
return;
|
||||
|
||||
}
|
||||
|
|
@ -70,21 +70,21 @@ handler_discovery(struct mg_connection *c, int ev, void *ev_data)
|
|||
int fd_answer = helper_connect_tcp_server(ip_buf, discovery_answer_port);
|
||||
if(fd_answer == -1)
|
||||
{
|
||||
LOG_ERROR("error during connecting\n");
|
||||
LOGGER_ERR("error during connecting\n");
|
||||
free(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
if((bytes_transferred = send(fd_answer, &payload_size, sizeof(payload_size), 0)) <= 0)
|
||||
{
|
||||
LOG_ERROR("error during sending\n");
|
||||
LOGGER_ERR("error during sending\n");
|
||||
free(payload);
|
||||
close(fd_answer);
|
||||
return;
|
||||
}
|
||||
if((bytes_transferred = send(fd_answer, payload, payload_size, 0)) <= 0)
|
||||
{
|
||||
LOG_ERROR("error during sending\n");
|
||||
LOGGER_ERR("error during sending\n");
|
||||
free(payload);
|
||||
close(fd_answer);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ handler_loop(struct mg_connection *c_mqtt)
|
|||
localtime_r(×tamp, &time_last);
|
||||
timestamp = time(NULL);
|
||||
localtime_r(×tamp, &time_now);
|
||||
LOG_TRACE("===== IDLE LOOP START =====\n");
|
||||
for(uint_fast8_t i = 0; i < global_controller->relay_count; ++i)
|
||||
{
|
||||
relay_t *relay = global_controller->relays[i];
|
||||
|
|
@ -52,7 +51,7 @@ handler_loop(struct mg_connection *c_mqtt)
|
|||
|
||||
if(is_on)
|
||||
{
|
||||
LOG_DEBUG("relay %d is active\n", i);
|
||||
LOGGER_DEBUG("relay %d is active\n", i);
|
||||
}
|
||||
|
||||
if(relay->is_on != is_on)
|
||||
|
|
@ -82,7 +81,7 @@ handler_loop(struct mg_connection *c_mqtt)
|
|||
driver_piface_set(global_config.relay_configs[i].pin, is_on);
|
||||
break;
|
||||
default:
|
||||
LOG_WARN("relay %d is not using a driver\n", i);
|
||||
LOGGER_WARNING("relay %d is not using a driver\n", i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,19 +23,19 @@ handler_mqtt(struct mg_connection *nc, int ev, void *p) {
|
|||
case MG_EV_MQTT_CONNACK:
|
||||
if(msg->connack_ret_code != MG_EV_MQTT_CONNACK_ACCEPTED)
|
||||
{
|
||||
LOG_INFO("Got MQTT connection error: %d\n", msg->connack_ret_code);
|
||||
LOGGER_INFO("Got MQTT connection error: %d\n", msg->connack_ret_code);
|
||||
break;
|
||||
}
|
||||
if(!global_connection_mqtt)
|
||||
{
|
||||
LOG_DEBUG("connected to MQTT server\n");
|
||||
LOGGER_DEBUG("connected to MQTT server\n");
|
||||
global_connection_mqtt = nc;
|
||||
}
|
||||
break;
|
||||
case MG_EV_CLOSE:
|
||||
if(global_connection_mqtt)
|
||||
{
|
||||
LOG_DEBUG("disconnected from MQTT server\n");
|
||||
LOGGER_DEBUG("disconnected from MQTT server\n");
|
||||
}
|
||||
global_connection_mqtt = NULL;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue