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 -4
View File
@@ -28,11 +28,17 @@ enum class return_code : unsigned
exit
};
return_code parseArguments(int argc, char *argv[], contractor::ContractorConfig &contractor_config)
return_code parseArguments(int argc,
char *argv[],
std::string &verbosity,
contractor::ContractorConfig &contractor_config)
{
// 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");
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 on command line
boost::program_options::options_description config_options("Configuration");
@@ -137,11 +143,11 @@ return_code parseArguments(int argc, char *argv[], contractor::ContractorConfig
int main(int argc, char *argv[]) try
{
util::LogPolicy::GetInstance().Unmute();
std::string verbosity;
contractor::ContractorConfig contractor_config;
const return_code result = parseArguments(argc, argv, contractor_config);
const return_code result = parseArguments(argc, argv, verbosity, contractor_config);
if (return_code::fail == result)
{
@@ -153,6 +159,8 @@ int main(int argc, char *argv[]) try
return EXIT_SUCCESS;
}
util::LogPolicy::GetInstance().SetLevel(verbosity);
contractor_config.UseDefaultOutputNames(contractor_config.base_path);
if (1 > contractor_config.requested_num_threads)