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:
parent
fb5bd818d9
commit
7323221e3b
@ -8,6 +8,7 @@ Feature: osrm-contract command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And stdout should contain "--core"
|
And stdout should contain "--core"
|
||||||
@ -22,6 +23,7 @@ Feature: osrm-contract command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And stdout should contain "--core"
|
And stdout should contain "--core"
|
||||||
@ -36,6 +38,7 @@ Feature: osrm-contract command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And stdout should contain "--core"
|
And stdout should contain "--core"
|
||||||
|
@ -8,6 +8,7 @@ Feature: osrm-customize command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And it should exit with an error
|
And it should exit with an error
|
||||||
@ -19,6 +20,7 @@ Feature: osrm-customize command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And it should exit successfully
|
And it should exit successfully
|
||||||
@ -30,6 +32,7 @@ Feature: osrm-customize command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And it should exit successfully
|
And it should exit successfully
|
||||||
|
@ -11,6 +11,7 @@ Feature: osrm-extract command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--profile"
|
And stdout should contain "--profile"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
@ -24,6 +25,7 @@ Feature: osrm-extract command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--profile"
|
And stdout should contain "--profile"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
@ -37,6 +39,7 @@ Feature: osrm-extract command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--profile"
|
And stdout should contain "--profile"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
|
@ -8,6 +8,7 @@ Feature: osrm-partition command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And stdout should contain "--balance"
|
And stdout should contain "--balance"
|
||||||
@ -24,6 +25,7 @@ Feature: osrm-partition command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And stdout should contain "--balance"
|
And stdout should contain "--balance"
|
||||||
@ -40,6 +42,7 @@ Feature: osrm-partition command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--threads"
|
And stdout should contain "--threads"
|
||||||
And stdout should contain "--balance"
|
And stdout should contain "--balance"
|
||||||
|
@ -11,6 +11,7 @@ Feature: osrm-routed command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "--trial"
|
And stdout should contain "--trial"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--ip"
|
And stdout should contain "--ip"
|
||||||
@ -30,6 +31,7 @@ Feature: osrm-routed command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "--trial"
|
And stdout should contain "--trial"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--ip"
|
And stdout should contain "--ip"
|
||||||
@ -49,6 +51,7 @@ Feature: osrm-routed command line options: help
|
|||||||
And stdout should contain "Options:"
|
And stdout should contain "Options:"
|
||||||
And stdout should contain "--version"
|
And stdout should contain "--version"
|
||||||
And stdout should contain "--help"
|
And stdout should contain "--help"
|
||||||
|
And stdout should contain "--verbosity"
|
||||||
And stdout should contain "--trial"
|
And stdout should contain "--trial"
|
||||||
And stdout should contain "Configuration:"
|
And stdout should contain "Configuration:"
|
||||||
And stdout should contain "--ip"
|
And stdout should contain "--ip"
|
||||||
|
@ -7,9 +7,10 @@
|
|||||||
|
|
||||||
enum LogLevel
|
enum LogLevel
|
||||||
{
|
{
|
||||||
logINFO,
|
logNONE,
|
||||||
logWARNING,
|
|
||||||
logERROR,
|
logERROR,
|
||||||
|
logWARNING,
|
||||||
|
logINFO,
|
||||||
logDEBUG
|
logDEBUG
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,14 +28,20 @@ class LogPolicy
|
|||||||
|
|
||||||
bool IsMute() const;
|
bool IsMute() const;
|
||||||
|
|
||||||
|
LogLevel GetLevel() const;
|
||||||
|
void SetLevel(LogLevel level);
|
||||||
|
void SetLevel(std::string const &level);
|
||||||
|
|
||||||
static LogPolicy &GetInstance();
|
static LogPolicy &GetInstance();
|
||||||
|
static std::string GetLevels();
|
||||||
|
|
||||||
LogPolicy(const LogPolicy &) = delete;
|
LogPolicy(const LogPolicy &) = delete;
|
||||||
LogPolicy &operator=(const LogPolicy &) = delete;
|
LogPolicy &operator=(const LogPolicy &) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogPolicy() : m_is_mute(true) {}
|
LogPolicy() : m_is_mute(true), m_level(logINFO) {}
|
||||||
std::atomic<bool> m_is_mute;
|
std::atomic<bool> m_is_mute;
|
||||||
|
LogLevel m_level;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
|
@ -28,11 +28,17 @@ enum class return_code : unsigned
|
|||||||
exit
|
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
|
// declare a group of options that will be allowed only on command line
|
||||||
boost::program_options::options_description generic_options("Options");
|
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
|
// declare a group of options that will be allowed on command line
|
||||||
boost::program_options::options_description config_options("Configuration");
|
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
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
|
|
||||||
util::LogPolicy::GetInstance().Unmute();
|
util::LogPolicy::GetInstance().Unmute();
|
||||||
|
std::string verbosity;
|
||||||
contractor::ContractorConfig contractor_config;
|
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)
|
if (return_code::fail == result)
|
||||||
{
|
{
|
||||||
@ -153,6 +159,8 @@ int main(int argc, char *argv[]) try
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
||||||
|
|
||||||
contractor_config.UseDefaultOutputNames(contractor_config.base_path);
|
contractor_config.UseDefaultOutputNames(contractor_config.base_path);
|
||||||
|
|
||||||
if (1 > contractor_config.requested_num_threads)
|
if (1 > contractor_config.requested_num_threads)
|
||||||
|
@ -21,12 +21,17 @@ enum class return_code : unsigned
|
|||||||
exit
|
exit
|
||||||
};
|
};
|
||||||
|
|
||||||
return_code
|
return_code parseArguments(int argc,
|
||||||
parseArguments(int argc, char *argv[], customizer::CustomizationConfig &customization_config)
|
char *argv[],
|
||||||
|
std::string &verbosity,
|
||||||
|
customizer::CustomizationConfig &customization_config)
|
||||||
{
|
{
|
||||||
// declare a group of options that will be allowed only on command line
|
// declare a group of options that will be allowed only on command line
|
||||||
boost::program_options::options_description generic_options("Options");
|
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
|
// declare a group of options that will be allowed both on command line
|
||||||
boost::program_options::options_description config_options("Configuration");
|
boost::program_options::options_description config_options("Configuration");
|
||||||
@ -130,9 +135,10 @@ parseArguments(int argc, char *argv[], customizer::CustomizationConfig &customiz
|
|||||||
int main(int argc, char *argv[]) try
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
util::LogPolicy::GetInstance().Unmute();
|
util::LogPolicy::GetInstance().Unmute();
|
||||||
|
std::string verbosity;
|
||||||
customizer::CustomizationConfig customization_config;
|
customizer::CustomizationConfig customization_config;
|
||||||
|
|
||||||
const auto result = parseArguments(argc, argv, customization_config);
|
const auto result = parseArguments(argc, argv, verbosity, customization_config);
|
||||||
|
|
||||||
if (return_code::fail == result)
|
if (return_code::fail == result)
|
||||||
{
|
{
|
||||||
@ -144,6 +150,8 @@ int main(int argc, char *argv[]) try
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
||||||
|
|
||||||
// set the default in/output names
|
// set the default in/output names
|
||||||
customization_config.UseDefaultOutputNames(customization_config.base_path);
|
customization_config.UseDefaultOutputNames(customization_config.base_path);
|
||||||
|
|
||||||
|
@ -24,11 +24,17 @@ enum class return_code : unsigned
|
|||||||
exit
|
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 a llowed 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");
|
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
|
// declare a group of options that will be allowed both on command line
|
||||||
boost::program_options::options_description config_options("Configuration");
|
boost::program_options::options_description config_options("Configuration");
|
||||||
@ -127,8 +133,9 @@ int main(int argc, char *argv[]) try
|
|||||||
{
|
{
|
||||||
util::LogPolicy::GetInstance().Unmute();
|
util::LogPolicy::GetInstance().Unmute();
|
||||||
extractor::ExtractorConfig extractor_config;
|
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)
|
if (return_code::fail == result)
|
||||||
{
|
{
|
||||||
@ -140,6 +147,8 @@ int main(int argc, char *argv[]) try
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
||||||
|
|
||||||
extractor_config.UseDefaultOutputNames(extractor_config.input_path);
|
extractor_config.UseDefaultOutputNames(extractor_config.input_path);
|
||||||
|
|
||||||
if (1 > extractor_config.requested_num_threads)
|
if (1 > extractor_config.requested_num_threads)
|
||||||
|
@ -69,11 +69,15 @@ void validate(boost::any &v, const std::vector<std::string> &values, MaxCellSize
|
|||||||
v = boost::any(MaxCellSizesArgument{output});
|
v = boost::any(MaxCellSizesArgument{output});
|
||||||
}
|
}
|
||||||
|
|
||||||
return_code parseArguments(int argc, char *argv[], partition::PartitionConfig &config)
|
return_code
|
||||||
|
parseArguments(int argc, char *argv[], std::string &verbosity, partition::PartitionConfig &config)
|
||||||
{
|
{
|
||||||
// declare a group of options that will be allowed only on command line
|
// declare a group of options that will be allowed only on command line
|
||||||
boost::program_options::options_description generic_options("Options");
|
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
|
// declare a group of options that will be allowed both on command line
|
||||||
boost::program_options::options_description config_options("Configuration");
|
boost::program_options::options_description config_options("Configuration");
|
||||||
@ -184,9 +188,10 @@ return_code parseArguments(int argc, char *argv[], partition::PartitionConfig &c
|
|||||||
int main(int argc, char *argv[]) try
|
int main(int argc, char *argv[]) try
|
||||||
{
|
{
|
||||||
util::LogPolicy::GetInstance().Unmute();
|
util::LogPolicy::GetInstance().Unmute();
|
||||||
|
std::string verbosity;
|
||||||
partition::PartitionConfig partition_config;
|
partition::PartitionConfig partition_config;
|
||||||
|
|
||||||
const auto result = parseArguments(argc, argv, partition_config);
|
const auto result = parseArguments(argc, argv, verbosity, partition_config);
|
||||||
|
|
||||||
if (return_code::fail == result)
|
if (return_code::fail == result)
|
||||||
{
|
{
|
||||||
@ -198,6 +203,8 @@ int main(int argc, char *argv[]) try
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
||||||
|
|
||||||
// set the default in/output names
|
// set the default in/output names
|
||||||
partition_config.UseDefaultOutputNames(partition_config.base_path);
|
partition_config.UseDefaultOutputNames(partition_config.base_path);
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ static EngineConfig::Algorithm stringToAlgorithm(std::string algorithm)
|
|||||||
// generate boost::program_options object for the routing part
|
// generate boost::program_options object for the routing part
|
||||||
inline unsigned generateServerProgramOptions(const int argc,
|
inline unsigned generateServerProgramOptions(const int argc,
|
||||||
const char *argv[],
|
const char *argv[],
|
||||||
|
std::string verbosity,
|
||||||
boost::filesystem::path &base_path,
|
boost::filesystem::path &base_path,
|
||||||
std::string &ip_address,
|
std::string &ip_address,
|
||||||
int &ip_port,
|
int &ip_port,
|
||||||
@ -88,8 +89,11 @@ inline unsigned generateServerProgramOptions(const int argc,
|
|||||||
// declare a group of options that will be allowed only on command line
|
// declare a group of options that will be allowed only on command line
|
||||||
boost::program_options::options_description generic_options("Options");
|
boost::program_options::options_description generic_options("Options");
|
||||||
generic_options.add_options() //
|
generic_options.add_options() //
|
||||||
("version,v", "Show version")("help,h", "Show this help message") //
|
("version,v", "Show version")("help,h", "Show this help message")(
|
||||||
("trial", value<bool>(&trial)->implicit_value(true), "Quit after initialization");
|
"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
|
// declare a group of options that will be allowed on command line
|
||||||
boost::program_options::options_description config_options("Configuration");
|
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;
|
int ip_port, requested_thread_num;
|
||||||
|
|
||||||
EngineConfig config;
|
EngineConfig config;
|
||||||
|
std::string verbosity;
|
||||||
boost::filesystem::path base_path;
|
boost::filesystem::path base_path;
|
||||||
std::string algorithm;
|
std::string algorithm;
|
||||||
const unsigned init_result = generateServerProgramOptions(argc,
|
const unsigned init_result = generateServerProgramOptions(argc,
|
||||||
argv,
|
argv,
|
||||||
|
verbosity,
|
||||||
base_path,
|
base_path,
|
||||||
ip_address,
|
ip_address,
|
||||||
ip_port,
|
ip_port,
|
||||||
@ -227,6 +233,9 @@ int main(int argc, const char *argv[]) try
|
|||||||
{
|
{
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
||||||
|
|
||||||
if (!base_path.empty())
|
if (!base_path.empty())
|
||||||
{
|
{
|
||||||
config.storage_config = storage::StorageConfig(base_path);
|
config.storage_config = storage::StorageConfig(base_path);
|
||||||
|
@ -52,12 +52,16 @@ void springClean()
|
|||||||
// generate boost::program_options object for the routing part
|
// generate boost::program_options object for the routing part
|
||||||
bool generateDataStoreOptions(const int argc,
|
bool generateDataStoreOptions(const int argc,
|
||||||
const char *argv[],
|
const char *argv[],
|
||||||
|
std::string &verbosity,
|
||||||
boost::filesystem::path &base_path,
|
boost::filesystem::path &base_path,
|
||||||
int &max_wait)
|
int &max_wait)
|
||||||
{
|
{
|
||||||
// declare a group of options that will be allowed only on command line
|
// declare a group of options that will be allowed only on command line
|
||||||
boost::program_options::options_description generic_options("Options");
|
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())(
|
||||||
"remove-locks,r", "Remove locks")("spring-clean,s",
|
"remove-locks,r", "Remove locks")("spring-clean,s",
|
||||||
"Spring-cleaning all shared memory regions");
|
"Spring-cleaning all shared memory regions");
|
||||||
|
|
||||||
@ -157,12 +161,16 @@ int main(const int argc, const char *argv[]) try
|
|||||||
|
|
||||||
util::LogPolicy::GetInstance().Unmute();
|
util::LogPolicy::GetInstance().Unmute();
|
||||||
|
|
||||||
|
std::string verbosity;
|
||||||
boost::filesystem::path base_path;
|
boost::filesystem::path base_path;
|
||||||
int max_wait = -1;
|
int max_wait = -1;
|
||||||
if (!generateDataStoreOptions(argc, argv, base_path, max_wait))
|
if (!generateDataStoreOptions(argc, argv, verbosity, base_path, max_wait))
|
||||||
{
|
{
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
util::LogPolicy::GetInstance().SetLevel(verbosity);
|
||||||
|
|
||||||
storage::StorageConfig config(base_path);
|
storage::StorageConfig config(base_path);
|
||||||
if (!config.IsValid())
|
if (!config.IsValid())
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "util/log.hpp"
|
#include "util/log.hpp"
|
||||||
#include "util/isatty.hpp"
|
#include "util/isatty.hpp"
|
||||||
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
@ -29,18 +30,49 @@ void LogPolicy::Mute() { m_is_mute = true; }
|
|||||||
|
|
||||||
bool LogPolicy::IsMute() const { return m_is_mute; }
|
bool LogPolicy::IsMute() const { return m_is_mute; }
|
||||||
|
|
||||||
|
LogLevel LogPolicy::GetLevel() const { return m_level; }
|
||||||
|
|
||||||
|
void LogPolicy::SetLevel(LogLevel level) { m_level = level; }
|
||||||
|
|
||||||
|
void LogPolicy::SetLevel(std::string const &level)
|
||||||
|
{
|
||||||
|
// Keep in sync with LogLevel definition
|
||||||
|
if (boost::iequals(level, "NONE"))
|
||||||
|
m_level = logNONE;
|
||||||
|
else if (boost::iequals(level, "ERROR"))
|
||||||
|
m_level = logERROR;
|
||||||
|
else if (boost::iequals(level, "WARNING"))
|
||||||
|
m_level = logWARNING;
|
||||||
|
else if (boost::iequals(level, "INFO"))
|
||||||
|
m_level = logINFO;
|
||||||
|
else if (boost::iequals(level, "DEBUG"))
|
||||||
|
m_level = logDEBUG;
|
||||||
|
else
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
LogPolicy &LogPolicy::GetInstance()
|
LogPolicy &LogPolicy::GetInstance()
|
||||||
{
|
{
|
||||||
static LogPolicy runningInstance;
|
static LogPolicy runningInstance;
|
||||||
return runningInstance;
|
return runningInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string LogPolicy::GetLevels()
|
||||||
|
{
|
||||||
|
// Keep in sync with LogLevel definition
|
||||||
|
return "NONE, ERROR, WARNING, INFO, DEBUG";
|
||||||
|
}
|
||||||
|
|
||||||
Log::Log(LogLevel level_, std::ostream &ostream) : level(level_), stream(ostream)
|
Log::Log(LogLevel level_, std::ostream &ostream) : level(level_), stream(ostream)
|
||||||
{
|
{
|
||||||
const bool is_terminal = IsStdoutATTY();
|
|
||||||
std::lock_guard<std::mutex> lock(get_mutex());
|
std::lock_guard<std::mutex> lock(get_mutex());
|
||||||
|
if (!LogPolicy::GetInstance().IsMute() && level <= LogPolicy::GetInstance().GetLevel())
|
||||||
|
{
|
||||||
|
const bool is_terminal = IsStdoutATTY();
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
|
case logNONE:
|
||||||
|
break;
|
||||||
case logWARNING:
|
case logWARNING:
|
||||||
stream << (is_terminal ? YELLOW : "") << "[warn] ";
|
stream << (is_terminal ? YELLOW : "") << "[warn] ";
|
||||||
break;
|
break;
|
||||||
@ -57,6 +89,7 @@ Log::Log(LogLevel level_, std::ostream &ostream) : level(level_), stream(ostream
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log::Log(LogLevel level_) : Log(level_, buffer) {}
|
Log::Log(LogLevel level_) : Log(level_, buffer) {}
|
||||||
|
|
||||||
@ -76,14 +109,16 @@ std::mutex &Log::get_mutex()
|
|||||||
Log::~Log()
|
Log::~Log()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(get_mutex());
|
std::lock_guard<std::mutex> lock(get_mutex());
|
||||||
const bool usestd = (&stream == &buffer);
|
if (!LogPolicy::GetInstance().IsMute() && level <= LogPolicy::GetInstance().GetLevel())
|
||||||
if (!LogPolicy::GetInstance().IsMute())
|
|
||||||
{
|
{
|
||||||
|
const bool usestd = (&stream == &buffer);
|
||||||
const bool is_terminal = IsStdoutATTY();
|
const bool is_terminal = IsStdoutATTY();
|
||||||
if (usestd)
|
if (usestd)
|
||||||
{
|
{
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
|
case logNONE:
|
||||||
|
break;
|
||||||
case logWARNING:
|
case logWARNING:
|
||||||
case logERROR:
|
case logERROR:
|
||||||
std::cerr << buffer.str();
|
std::cerr << buffer.str();
|
||||||
|
Loading…
Reference in New Issue
Block a user