aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-04-20 13:38:20 -0700
committerMartin Braun <martin.braun@ettus.com>2017-04-20 13:38:20 -0700
commit107c105e403f4c4cbd2257219c088d62a3875082 (patch)
treee79f715697e497756ffebd472cc7f709d2ca6ede /host
parent372228d2a61337ca89a139eec666e531e6723e74 (diff)
downloaduhd-107c105e403f4c4cbd2257219c088d62a3875082.tar.gz
uhd-107c105e403f4c4cbd2257219c088d62a3875082.tar.bz2
uhd-107c105e403f4c4cbd2257219c088d62a3875082.zip
log: Fix missing add_logger, fix clearing of queue
Diffstat (limited to 'host')
-rw-r--r--host/lib/utils/log.cpp27
-rw-r--r--host/tests/log_test.cpp13
2 files changed, 35 insertions, 5 deletions
diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp
index 1d87a0b3d..5d0a9cf5b 100644
--- a/host/lib/utils/log.cpp
+++ b/host/lib/utils/log.cpp
@@ -221,13 +221,29 @@ public:
for (const auto &logger : _loggers) {
auto level = logger_level.find(logger.first);
if(level != logger_level.end() && log_info.verbosity < level->second){
- UHD_VAR(level->second)
- continue;
+ continue;
}
logger.second(log_info);
}
}
}
+
+ // Exit procedure: Clear the queue
+ uhd::log::logging_info log_info;
+ while (_log_queue.pop_with_haste(log_info)) {
+ for (const auto &logger : _loggers) {
+ auto level = logger_level.find(logger.first);
+ if (level != logger_level.end() && log_info.verbosity < level->second){
+ continue;
+ }
+ logger.second(log_info);
+ }
+ }
+ }
+
+ void add_logger(const std::string &key, uhd::log::log_fn_t logger_fn)
+ {
+ _loggers[key] = logger_fn;
}
private:
@@ -297,6 +313,13 @@ uhd::_log::log::~log(void)
}
}
+
+void
+uhd::log::add_logger(const std::string &key, log_fn_t logger_fn)
+{
+ log_rs().add_logger(key, logger_fn);
+}
+
void
uhd::log::set_log_level(uhd::log::severity_level level){
log_rs().global_level = level;
diff --git a/host/tests/log_test.cpp b/host/tests/log_test.cpp
index 1973a83ff..d42e5ffbd 100644
--- a/host/tests/log_test.cpp
+++ b/host/tests/log_test.cpp
@@ -20,9 +20,17 @@
#include <iostream>
BOOST_AUTO_TEST_CASE(test_messages){
- uhd::log::set_log_level(uhd::log::info);
+ uhd::log::set_log_level(uhd::log::debug);
uhd::log::set_console_level(uhd::log::info);
- std::cerr << "---begin print test ---" << std::endl;
+ uhd::log::add_logger("test",
+ [](const uhd::log::logging_info &I){
+ std::cout << "<TEST> " << I.message << std::endl;
+ }
+ );
+ uhd::log::set_logger_level("test", uhd::log::debug);
+ UHD_LOGGER_DEBUG("logger_test") <<
+ "This is a test print for a debug log."
+ ;
UHD_LOGGER_INFO("logger_test") <<
"This is a test print for a info log."
;
@@ -35,5 +43,4 @@ BOOST_AUTO_TEST_CASE(test_messages){
UHD_HERE();
const int x = 42;
UHD_VAR(x);
- std::cerr << "---end print test ---" << std::endl;
}