Refactor logging, improve error handling workflow, clang-format. (#3385)
This commit is contained in:
+37
-49
@@ -1,5 +1,5 @@
|
||||
#include "server/server.hpp"
|
||||
#include "util/simple_logger.hpp"
|
||||
#include "util/log.hpp"
|
||||
#include "util/version.hpp"
|
||||
|
||||
#include "osrm/engine_config.hpp"
|
||||
@@ -136,19 +136,19 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
}
|
||||
catch (const boost::program_options::error &e)
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "[error] " << e.what();
|
||||
util::Log(logERROR) << e.what();
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
if (option_variables.count("version"))
|
||||
{
|
||||
util::SimpleLogger().Write() << OSRM_VERSION;
|
||||
std::cout << OSRM_VERSION << std::endl;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
if (option_variables.count("help"))
|
||||
{
|
||||
util::SimpleLogger().Write() << visible_options;
|
||||
std::cout << visible_options;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
@@ -164,11 +164,10 @@ inline unsigned generateServerProgramOptions(const int argc,
|
||||
}
|
||||
else if (use_shared_memory && option_variables.count("base"))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< "Shared memory settings conflict with path settings.";
|
||||
util::Log(logWARNING) << "Shared memory settings conflict with path settings.";
|
||||
}
|
||||
|
||||
util::SimpleLogger().Write() << visible_options;
|
||||
std::cout << visible_options;
|
||||
return INIT_OK_DO_NOT_START_ENGINE;
|
||||
}
|
||||
|
||||
@@ -211,69 +210,59 @@ int main(int argc, const char *argv[]) try
|
||||
{
|
||||
if (base_path.empty() != config.use_shared_memory)
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "Path settings and shared memory conflicts.";
|
||||
util::Log(logWARNING) << "Path settings and shared memory conflicts.";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.ram_index_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.ram_index_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.ram_index_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.file_index_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.file_index_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.file_index_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.hsgr_data_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.hsgr_data_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.hsgr_data_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.nodes_data_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.nodes_data_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.nodes_data_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.edges_data_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.edges_data_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.edges_data_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.core_data_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.core_data_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.core_data_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.geometries_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.geometries_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.geometries_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.timestamp_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.timestamp_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.timestamp_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.datasource_names_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< config.storage_config.datasource_names_path << " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.datasource_names_path
|
||||
<< " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.datasource_indexes_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< config.storage_config.datasource_indexes_path << " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.datasource_indexes_path
|
||||
<< " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.names_data_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.names_data_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.names_data_path << " is not found";
|
||||
}
|
||||
if (!boost::filesystem::is_regular_file(config.storage_config.properties_path))
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << config.storage_config.properties_path
|
||||
<< " is not found";
|
||||
util::Log(logWARNING) << config.storage_config.properties_path << " is not found";
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
@@ -287,7 +276,7 @@ int main(int argc, const char *argv[]) try
|
||||
if (should_lock && -1 == mlockall(MCL_CURRENT | MCL_FUTURE))
|
||||
{
|
||||
could_lock = false;
|
||||
util::SimpleLogger().Write(logWARNING) << "memory could not be locked to RAM";
|
||||
util::Log(logWARNING) << "memory could not be locked to RAM";
|
||||
}
|
||||
}
|
||||
~MemoryLocker()
|
||||
@@ -298,16 +287,16 @@ int main(int argc, const char *argv[]) try
|
||||
bool should_lock = false, could_lock = true;
|
||||
} memory_locker(config.use_shared_memory);
|
||||
#endif
|
||||
util::SimpleLogger().Write() << "starting up engines, " << OSRM_VERSION;
|
||||
util::Log() << "starting up engines, " << OSRM_VERSION;
|
||||
|
||||
if (config.use_shared_memory)
|
||||
{
|
||||
util::SimpleLogger().Write() << "Loading from shared memory";
|
||||
util::Log() << "Loading from shared memory";
|
||||
}
|
||||
|
||||
util::SimpleLogger().Write() << "Threads: " << requested_thread_num;
|
||||
util::SimpleLogger().Write() << "IP address: " << ip_address;
|
||||
util::SimpleLogger().Write() << "IP port: " << ip_port;
|
||||
util::Log() << "Threads: " << requested_thread_num;
|
||||
util::Log() << "IP address: " << ip_address;
|
||||
util::Log() << "IP port: " << ip_port;
|
||||
|
||||
#ifndef _WIN32
|
||||
int sig = 0;
|
||||
@@ -324,7 +313,7 @@ int main(int argc, const char *argv[]) try
|
||||
|
||||
if (trial_run)
|
||||
{
|
||||
util::SimpleLogger().Write() << "trial run, quitting after successful initialization";
|
||||
util::Log() << "trial run, quitting after successful initialization";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -343,7 +332,7 @@ int main(int argc, const char *argv[]) try
|
||||
sigaddset(&wait_mask, SIGQUIT);
|
||||
sigaddset(&wait_mask, SIGTERM);
|
||||
pthread_sigmask(SIG_BLOCK, &wait_mask, nullptr);
|
||||
util::SimpleLogger().Write() << "running and waiting for requests";
|
||||
util::Log() << "running and waiting for requests";
|
||||
if (std::getenv("SIGNAL_PARENT_WHEN_READY"))
|
||||
{
|
||||
kill(getppid(), SIGUSR1);
|
||||
@@ -353,12 +342,12 @@ int main(int argc, const char *argv[]) try
|
||||
// Set console control handler to allow server to be stopped.
|
||||
console_ctrl_function = std::bind(&server::Server::Stop, routing_server);
|
||||
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
|
||||
util::SimpleLogger().Write() << "running and waiting for requests";
|
||||
util::Log() << "running and waiting for requests";
|
||||
routing_server->Run();
|
||||
#endif
|
||||
util::SimpleLogger().Write() << "initiating shutdown";
|
||||
util::Log() << "initiating shutdown";
|
||||
routing_server->Stop();
|
||||
util::SimpleLogger().Write() << "stopping threads";
|
||||
util::Log() << "stopping threads";
|
||||
|
||||
auto status = future.wait_for(std::chrono::seconds(2));
|
||||
|
||||
@@ -368,19 +357,18 @@ int main(int argc, const char *argv[]) try
|
||||
}
|
||||
else
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "Didn't exit within 2 seconds. Hard abort!";
|
||||
util::Log(logWARNING) << "Didn't exit within 2 seconds. Hard abort!";
|
||||
server_task.reset(); // just kill it
|
||||
}
|
||||
}
|
||||
|
||||
util::SimpleLogger().Write() << "freeing objects";
|
||||
util::Log() << "freeing objects";
|
||||
routing_server.reset();
|
||||
util::SimpleLogger().Write() << "shutdown completed";
|
||||
util::Log() << "shutdown completed";
|
||||
}
|
||||
catch (const std::bad_alloc &e)
|
||||
{
|
||||
util::SimpleLogger().Write(logWARNING) << "[exception] " << e.what();
|
||||
util::SimpleLogger().Write(logWARNING)
|
||||
<< "Please provide more memory or consider using a larger swapfile";
|
||||
util::Log(logWARNING) << "[exception] " << e.what();
|
||||
util::Log(logWARNING) << "Please provide more memory or consider using a larger swapfile";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user