fix: better logging behaviour
This commit is contained in:
parent
3e6d0333b7
commit
398019afe8
36 changed files with 256 additions and 188 deletions
src
28
src/main.c
28
src/main.c
|
@ -2,6 +2,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <mongoose.h>
|
||||
#include <router.h>
|
||||
|
@ -20,7 +21,7 @@ static struct mg_mgr mgr;
|
|||
static void
|
||||
terminate(int signum)
|
||||
{
|
||||
LOG_INFO("terminating controller (%d)\n", signum);
|
||||
LOGGER_INFO("terminating controller (%d)\n", signum);
|
||||
|
||||
mg_mgr_free(&mgr);
|
||||
|
||||
|
@ -29,6 +30,8 @@ terminate(int signum)
|
|||
router_free();
|
||||
status_free();
|
||||
|
||||
closelog();
|
||||
|
||||
exit(signum);
|
||||
}
|
||||
|
||||
|
@ -47,15 +50,20 @@ main(int argc, const char** argv)
|
|||
signal(SIGABRT, terminate);
|
||||
signal(SIGTERM, terminate);
|
||||
|
||||
setlogmask(LOG_UPTO(LOG_INFO));
|
||||
|
||||
|
||||
|
||||
/******************** LOAD CONFIG ********************/
|
||||
|
||||
global_config.file = "core.ini";
|
||||
global_config.log_level = LOG_LEVEL_INFO;
|
||||
global_config.discovery_port = 4421;
|
||||
global_config.mqtt_port = 1885;
|
||||
global_config.server_port = 5000;
|
||||
|
||||
global_config.log_level = LOG_INFO;
|
||||
global_config.log_file = stdout;
|
||||
|
||||
strcpy(global_config.user, "");
|
||||
strcpy(global_config.group, "");
|
||||
|
||||
|
@ -70,12 +78,12 @@ main(int argc, const char** argv)
|
|||
FILE * const ini_file = fopen(global_config.file, "rb");
|
||||
if(ini_file == NULL)
|
||||
{
|
||||
LOG_FATAL("config file '%s' was not found\n", global_config.file);
|
||||
LOGGER_CRIT("config file '%s' was not found\n", global_config.file);
|
||||
exit(1);
|
||||
}
|
||||
if(load_ini_file( ini_file, INI_DEFAULT_FORMAT, NULL, config_load, &global_config))
|
||||
{
|
||||
LOG_FATAL("unable to parse ini file\n");
|
||||
LOGGER_CRIT("unable to parse ini file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -86,6 +94,12 @@ main(int argc, const char** argv)
|
|||
global_config.http_server_opts.enable_directory_listing = "no";
|
||||
global_config.http_server_opts.extra_headers = "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: *\r\nAccess-Control-Allow-Methods: *";
|
||||
|
||||
if(global_config.log_file == NULL)
|
||||
{
|
||||
global_config.log_file = stdout;
|
||||
}
|
||||
openlog("emgauwa-core", 0, LOG_USER);
|
||||
|
||||
|
||||
/******************** SETUP CONNECTION ********************/
|
||||
|
||||
|
@ -98,7 +112,7 @@ main(int argc, const char** argv)
|
|||
struct mg_connection *c_http = mg_bind(&mgr, address, handler_http);
|
||||
if(c_http == NULL)
|
||||
{
|
||||
LOG_FATAL("failed to bind http server to port %u\n", global_config.server_port);
|
||||
LOGGER_CRIT("failed to bind http server to port %u\n", global_config.server_port);
|
||||
exit(1);
|
||||
}
|
||||
mg_set_protocol_http_websocket(c_http);
|
||||
|
@ -107,7 +121,7 @@ main(int argc, const char** argv)
|
|||
struct mg_connection *c_mqtt = mg_bind(&mgr, address, handler_mqtt);
|
||||
if(c_mqtt == NULL)
|
||||
{
|
||||
LOG_FATAL("failed to bind mqtt server to port %u\n", global_config.mqtt_port);
|
||||
LOGGER_CRIT("failed to bind mqtt server to port %u\n", global_config.mqtt_port);
|
||||
exit(1);
|
||||
}
|
||||
mg_mqtt_broker_init(&brk, NULL);
|
||||
|
@ -123,7 +137,7 @@ main(int argc, const char** argv)
|
|||
|
||||
if(rc)
|
||||
{
|
||||
LOG_FATAL("can't open database: %s\n", sqlite3_errmsg(global_database));
|
||||
LOGGER_CRIT("can't open database: %s\n", sqlite3_errmsg(global_database));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue