diff --git a/features/options/extract/verbosity.feature b/features/options/extract/verbosity.feature new file mode 100644 index 000000000..d18efcb72 --- /dev/null +++ b/features/options/extract/verbosity.feature @@ -0,0 +1,32 @@ +@extract +Feature: osrm-extract must be silent with NONE + + Background: + Given the node map + """ + a b + """ + And the ways + | nodes | + | ab | + And the data has been saved to disk + + Scenario: osrm-extract - Passing base file with verbosity NONE + Given the profile file + """ + functions = require('testbot') + + function way_function(profile, way, result) + result.forward_mode = mode.driving + result.forward_speed = 1 + end + + functions.process_way = way_function + return functions + """ + When I run "osrm-extract --profile {profile_file} {osm_file} --verbosity NONE" + Then it should exit successfully + And stdout should not contain "[info]" + And stdout should not contain "[error]" + And stdout should not contain "10%" + And stderr should be empty diff --git a/include/util/log.hpp b/include/util/log.hpp index 42cb23978..d4b5f9c47 100644 --- a/include/util/log.hpp +++ b/include/util/log.hpp @@ -53,10 +53,40 @@ class Log virtual ~Log(); std::mutex &get_mutex(); - template inline std::ostream &operator<<(const T &data) { return stream << data; } + template inline Log &operator<<(const T &data) + { + const auto &policy = LogPolicy::GetInstance(); + if (!policy.IsMute() && level <= policy.GetLevel()) + { + stream << data; + } + return *this; + } + + template inline Log &operator<<(const std::atomic &data) + { + const auto &policy = LogPolicy::GetInstance(); + if (!policy.IsMute() && level <= policy.GetLevel()) + { + stream << T(data); + } + return *this; + } + + typedef std::ostream &(manip)(std::ostream &); + + inline Log &operator<<(manip &m) + { + const auto &policy = LogPolicy::GetInstance(); + if (!policy.IsMute() && level <= policy.GetLevel()) + { + stream << m; + } + return *this; + } protected: - LogLevel level; + const LogLevel level; std::ostringstream buffer; std::ostream &stream; }; diff --git a/include/util/percent.hpp b/include/util/percent.hpp index 9bf11832e..1ec1f2c13 100644 --- a/include/util/percent.hpp +++ b/include/util/percent.hpp @@ -83,7 +83,7 @@ class Percent // When not on a TTY, print newlines after each progress indicator so // so that progress is visible to line-buffered logging systems if (!IsStdoutATTY()) - log << "" << std::endl; + log << std::endl; } } }; diff --git a/src/util/log.cpp b/src/util/log.cpp index 1c17f2bc7..602012bd9 100644 --- a/src/util/log.cpp +++ b/src/util/log.cpp @@ -48,7 +48,7 @@ void LogPolicy::SetLevel(std::string const &level) else if (boost::iequals(level, "DEBUG")) m_level = logDEBUG; else - ; + m_level = logINFO; } LogPolicy &LogPolicy::GetInstance()