Add --verbosity,-l command line option

Allow to fine-control logging verbosity via command line
and LogPolicy setting (useful when OSRM used as library).

Closes #4299
This commit is contained in:
Mateusz Loskot
2017-08-28 21:20:13 +02:00
committed by Patrick Niklaus
parent fb5bd818d9
commit 7323221e3b
13 changed files with 144 additions and 38 deletions
+12 -3
View File
@@ -68,6 +68,7 @@ static EngineConfig::Algorithm stringToAlgorithm(std::string algorithm)
// generate boost::program_options object for the routing part
inline unsigned generateServerProgramOptions(const int argc,
const char *argv[],
std::string verbosity,
boost::filesystem::path &base_path,
std::string &ip_address,
int &ip_port,
@@ -87,9 +88,12 @@ inline unsigned generateServerProgramOptions(const int argc,
// declare a group of options that will be allowed only on command line
boost::program_options::options_description generic_options("Options");
generic_options.add_options() //
("version,v", "Show version")("help,h", "Show this help message") //
("trial", value<bool>(&trial)->implicit_value(true), "Quit after initialization");
generic_options.add_options() //
("version,v", "Show version")("help,h", "Show this help message")(
"verbosity,l",
boost::program_options::value<std::string>(&verbosity)->default_value("INFO"),
std::string("Log verbosity level: " + util::LogPolicy::GetLevels()).c_str())(
"trial", value<bool>(&trial)->implicit_value(true), "Quit after initialization");
// declare a group of options that will be allowed on command line
boost::program_options::options_description config_options("Configuration");
@@ -202,10 +206,12 @@ int main(int argc, const char *argv[]) try
int ip_port, requested_thread_num;
EngineConfig config;
std::string verbosity;
boost::filesystem::path base_path;
std::string algorithm;
const unsigned init_result = generateServerProgramOptions(argc,
argv,
verbosity,
base_path,
ip_address,
ip_port,
@@ -227,6 +233,9 @@ int main(int argc, const char *argv[]) try
{
return EXIT_FAILURE;
}
util::LogPolicy::GetInstance().SetLevel(verbosity);
if (!base_path.empty())
{
config.storage_config = storage::StorageConfig(base_path);