aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorLane Kolbly <lane.kolbly@ni.com>2022-02-23 17:04:48 -0600
committerAaron Rossetto <aaron.rossetto@ni.com>2022-03-11 09:10:04 -0600
commit7484b4f095e3bf7c16fc2f91dc1a78f04397bf01 (patch)
tree03954f38370ba6e96acdac6eff6de271c3250195 /host/lib
parent6d58b692e4d26f662e6b2317e9c65043d398f00e (diff)
downloaduhd-7484b4f095e3bf7c16fc2f91dc1a78f04397bf01.tar.gz
uhd-7484b4f095e3bf7c16fc2f91dc1a78f04397bf01.tar.bz2
uhd-7484b4f095e3bf7c16fc2f91dc1a78f04397bf01.zip
host: test: Add UHD_UNITTEST_LOG_LEVEL override
Diffstat (limited to 'host/lib')
-rw-r--r--host/lib/utils/log.cpp54
1 files changed, 35 insertions, 19 deletions
diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp
index cf18e00c7..031066e65 100644
--- a/host/lib/utils/log.cpp
+++ b/host/lib/utils/log.cpp
@@ -100,6 +100,35 @@ inline std::string path_to_filename(std::string path)
} // namespace
+namespace uhd { namespace log {
+
+boost::optional<uhd::log::severity_level> parse_log_level_from_string(
+ const std::string& log_level_str)
+{
+ if (std::isdigit(log_level_str[0])) {
+ const uhd::log::severity_level log_level_num =
+ uhd::log::severity_level(std::stoi(log_level_str));
+ if (log_level_num >= uhd::log::trace && log_level_num <= uhd::log::fatal) {
+ return log_level_num;
+ } else {
+ std::cerr << "[LOG] Failed to set log level to: " << log_level_str;
+ return boost::none;
+ }
+ }
+
+#define if_loglevel_equal(name) else if (log_level_str == #name) return uhd::log::name
+ if_loglevel_equal(trace);
+ if_loglevel_equal(debug);
+ if_loglevel_equal(info);
+ if_loglevel_equal(warning);
+ if_loglevel_equal(error);
+ if_loglevel_equal(fatal);
+ if_loglevel_equal(off);
+ return boost::none;
+}
+
+}}
+
/***********************************************************************
* Logger backends
**********************************************************************/
@@ -407,26 +436,13 @@ private:
uhd::log::severity_level _get_log_level(
const std::string& log_level_str, const uhd::log::severity_level& previous_level)
{
- if (std::isdigit(log_level_str[0])) {
- const uhd::log::severity_level log_level_num =
- uhd::log::severity_level(std::stoi(log_level_str));
- if (log_level_num >= uhd::log::trace and log_level_num <= uhd::log::fatal) {
- return log_level_num;
- } else {
- std::cerr << "[LOG] Failed to set log level to: " << log_level_str;
- return previous_level;
- }
+ boost::optional<uhd::log::severity_level> parsed_level =
+ uhd::log::parse_log_level_from_string(log_level_str);
+ if (parsed_level) {
+ return *parsed_level;
+ } else {
+ return previous_level;
}
-
-#define if_loglevel_equal(name) else if (log_level_str == #name) return uhd::log::name
- if_loglevel_equal(trace);
- if_loglevel_equal(debug);
- if_loglevel_equal(info);
- if_loglevel_equal(warning);
- if_loglevel_equal(error);
- if_loglevel_equal(fatal);
- if_loglevel_equal(off);
- return previous_level;
}
void _setup_console_logging()