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
+13 -4
View File
@@ -24,11 +24,17 @@ enum class return_code : unsigned
exit
};
return_code parseArguments(int argc, char *argv[], extractor::ExtractorConfig &extractor_config)
return_code parseArguments(int argc,
char *argv[],
std::string &verbosity,
extractor::ExtractorConfig &extractor_config)
{
// declare a group of options that will be allowed only on command line
// declare a group of options that will be a llowed 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");
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());
// declare a group of options that will be allowed both on command line
boost::program_options::options_description config_options("Configuration");
@@ -127,8 +133,9 @@ int main(int argc, char *argv[]) try
{
util::LogPolicy::GetInstance().Unmute();
extractor::ExtractorConfig extractor_config;
std::string verbosity;
const auto result = parseArguments(argc, argv, extractor_config);
const auto result = parseArguments(argc, argv, verbosity, extractor_config);
if (return_code::fail == result)
{
@@ -140,6 +147,8 @@ int main(int argc, char *argv[]) try
return EXIT_SUCCESS;
}
util::LogPolicy::GetInstance().SetLevel(verbosity);
extractor_config.UseDefaultOutputNames(extractor_config.input_path);
if (1 > extractor_config.requested_num_threads)