From bd7ed780f5de9b3d11352a005841b19fe7fd7de1 Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@cnes.fr> Date: Wed, 21 Feb 2018 15:37:22 +0100 Subject: [PATCH] ENH: Read log level from env variable in Configuration manager --- .../Common/include/otbConfigurationManager.h | 6 +++- .../Common/src/otbConfigurationManager.cxx | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Modules/Core/Common/include/otbConfigurationManager.h b/Modules/Core/Common/include/otbConfigurationManager.h index 8c8f9af7cc..4ac1dcc372 100644 --- a/Modules/Core/Common/include/otbConfigurationManager.h +++ b/Modules/Core/Common/include/otbConfigurationManager.h @@ -31,7 +31,7 @@ #include <string> #include <boost/cstdint.hpp> - +#include "itkLoggerBase.h" #include "OTBCommonExport.h" namespace otb @@ -84,6 +84,10 @@ public: */ static RAMValueType GetMaxRAMHint(); + + static itk::LoggerBase::PriorityLevelType GetLoggerLevel(); + + private: ConfigurationManager(); //purposely not implemented ~ConfigurationManager(); //purposely not implemented diff --git a/Modules/Core/Common/src/otbConfigurationManager.cxx b/Modules/Core/Common/src/otbConfigurationManager.cxx index de0ea04579..4add4e19be 100644 --- a/Modules/Core/Common/src/otbConfigurationManager.cxx +++ b/Modules/Core/Common/src/otbConfigurationManager.cxx @@ -23,6 +23,8 @@ #include "itksys/SystemTools.hxx" #include <cstdlib> +#include <algorithm> +#include <string> namespace otb { @@ -59,6 +61,35 @@ ConfigurationManager::RAMValueType ConfigurationManager::GetMaxRAMHint() } return value; +} + + +#define level_macro(x) \ + { \ + std::string target = #x; \ + if(std::equal(svalue.begin(),svalue.end(),target.begin(),target.end())) \ + level = itk::LoggerBase::x; \ + } \ + + +itk::LoggerBase::PriorityLevelType ConfigurationManager::GetLoggerLevel() +{ + std::string svalue; + + #ifndef NDEBUG + itk::LoggerBase::PriorityLevelType level = itk::LoggerBase::DEBUG; + #else + itk::LoggerBase::PriorityLevelType level = itk::LoggerBase::WARNING; + #endif + + if(itksys::SystemTools::GetEnv("OTB_LOGGER_LEVEL",svalue)) + { + level_macro(DEBUG); + level_macro(WARNING); + level_macro(INFO); + } + return level; } + } -- GitLab