aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/utils
diff options
context:
space:
mode:
authorAndrej Rode <andrej.rode@ettus.com>2017-02-22 15:02:25 -0800
committerMartin Braun <martin.braun@ettus.com>2017-02-23 14:59:31 -0800
commit644ee82123987b4271e97f088c758f1eee86c880 (patch)
tree3ba4d1c105f652411457774afa24b2dc8b4c94bb /host/lib/utils
parent5964adcdc32a94c5a259a22b1bca406a3bf7b106 (diff)
downloaduhd-644ee82123987b4271e97f088c758f1eee86c880.tar.gz
uhd-644ee82123987b4271e97f088c758f1eee86c880.tar.bz2
uhd-644ee82123987b4271e97f088c758f1eee86c880.zip
utils: provide fallback to previous loglevel on reading environment/defines
Diffstat (limited to 'host/lib/utils')
-rw-r--r--host/lib/utils/log.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp
index 7fc28f122..60614d29e 100644
--- a/host/lib/utils/log.cpp
+++ b/host/lib/utils/log.cpp
@@ -39,7 +39,7 @@ public:
uhd::log::severity_level file_level;
uhd::log::severity_level console_level;
- log_resource_type(void){
+ log_resource_type(void): level(uhd::log::info), file_level(uhd::log::info), console_level(uhd::log::info){
//file lock pointer must be null
_file_lock = NULL;
@@ -54,13 +54,13 @@ public:
//allow override from macro definition
#ifdef UHD_LOG_MIN_LEVEL
- this->level = _get_log_level(BOOST_STRINGIZE(UHD_LOG_MIN_LEVEL));
+ this->level = _get_log_level(BOOST_STRINGIZE(UHD_LOG_MIN_LEVEL), this->level);
#endif
#if defined(UHD_LOG_FILE_LEVEL) && defined(UHD_LOG_FILE_PATH)
- this->file_level = _get_log_level(BOOST_STRINGIZE(UHD_LOG_FILE_LEVEL));
+ this->file_level = _get_log_level(BOOST_STRINGIZE(UHD_LOG_FILE_LEVEL), this->file_level);
#endif
#ifdef UHD_LOG_CONSOLE_LEVEL
- this->console_level = _get_log_level(BOOST_STRINGIZE(UHD_LOG_CONSOLE_LEVEL));
+ this->console_level = _get_log_level(BOOST_STRINGIZE(UHD_LOG_CONSOLE_LEVEL), this->console_level);
#endif
#ifdef UHD_LOG_FILE
this->log_file_target = BOOST_STRINGIZE(UHD_LOG_FILE);
@@ -69,13 +69,13 @@ public:
//allow override from environment variables
const char * log_level_env = std::getenv("UHD_LOG_LEVEL");
- if (log_level_env != NULL && log_level_env[0] != '\0') this->level = _get_log_level(log_level_env);
+ if (log_level_env != NULL && log_level_env[0] != '\0') this->level = _get_log_level(log_level_env, this->level);
const char * log_file_level_env = std::getenv("UHD_LOG_FILE_LEVEL");
- if (log_file_level_env != NULL && log_file_level_env[0] != '\0') this->file_level = _get_log_level(log_file_level_env);
+ if (log_file_level_env != NULL && log_file_level_env[0] != '\0') this->file_level = _get_log_level(log_file_level_env, this->file_level);
const char * log_console_level_env = std::getenv("UHD_LOG_CONSOLE_LEVEL");
- if (log_console_level_env != NULL && log_console_level_env[0] != '\0') this->console_level = _get_log_level(log_console_level_env);
+ if (log_console_level_env != NULL && log_console_level_env[0] != '\0') this->console_level = _get_log_level(log_console_level_env, this->console_level);
const char* log_file_env = std::getenv("UHD_LOG_FILE");
if ((log_file_env != NULL) && (log_file_env[0] != '\0')) {
@@ -109,13 +109,16 @@ private:
//! set the log level from a string that is either a digit or an enum name
bool file_logging;
std::string log_file_target;
- uhd::log::severity_level _get_log_level(const std::string &log_level_str){
+ 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{
+ return previous_level;
}
}
@@ -127,7 +130,8 @@ private:
if_loglevel_equal(warning);
if_loglevel_equal(error);
if_loglevel_equal(fatal);
- return uhd::log::off;
+ if_loglevel_equal(off);
+ return previous_level;
}
//file stream and lock: