diff --git a/Modules/Core/Common/include/otbMacro.h b/Modules/Core/Common/include/otbMacro.h index 84a5ffc77372e6bc0f6500b0f0a1e14146cf68fe..4ffd8eed9b6d575860bc717603dead28af374dd6 100644 --- a/Modules/Core/Common/include/otbMacro.h +++ b/Modules/Core/Common/include/otbMacro.h @@ -31,6 +31,7 @@ #include "itkMacro.h" #include "itkObject.h" #include "otbConfigure.h" +#include "otbLogger.h" /** * \namespace otb @@ -42,86 +43,37 @@ namespace otb { } // end namespace otb - this is here for documentation purposes -/** This macro is used to print debug (or other information). They are - * also used to catch errors, etc. Example usage looks like: - * itkDebugMacro(<< "this is debug info" << this->SomeVariable); */ -#define otbDebugMacro(x) itkDebugMacro(x) -/* { if ( this->GetDebug() && *::itk::Object::GetGlobalWarningDisplay()) \ - { std::ostringstream itkmsg; \ - itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \ - << this->GetNameOfClass() << " (" << this << "): " x \ - << "\n\n"; \ - ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); } \ -}*/ - -#define otbMsgDebugMacro(x) \ - { \ - if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \ - { \ - std::ostringstream itkmsg; \ - itkmsg << " Msg Debug: " x << "\n"; \ - ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \ - } \ - } +#define otbFileContext(x) \ + << "file " __FILE__ ", line " << __LINE__<<", " x -#ifndef NDEBUG -#define otbGenericMsgDebugMacro(x) \ - { \ - if (::itk::Object::GetGlobalWarningDisplay()) \ - { \ - std::ostringstream itkmsg; \ - itkmsg << " Generic Msg Debug: " x << "\n"; \ - ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \ - } \ - } -#else -#define otbGenericMsgDebugMacro(x) -#endif +#define otbClassContext(x) \ + << this->GetNameOfClass() << " (" << this << "): " x -#define otbGenericMsgTestingMacro(x) \ - { \ - std::cout x << std::endl; \ - } +#define otbLogMacro(level,msg) \ + { \ + std::ostringstream itkmsg; \ + itkmsg msg << "\n"; \ + otb::Logger::Instance()->level(itkmsg.str().c_str()); \ + } -#ifdef OTB_SHOW_ALL_MSG_DEBUG -#define otbMsgDevMacro(x) \ - { \ - { \ - std::ostringstream itkmsg; \ - itkmsg << " Msg Dev: (" << __FILE__ << ":" << __LINE__ << ") " x << "\n"; \ - ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \ - } \ - } -#else -#define otbMsgDevMacro(x) -#endif - -/** This macro is used to print warning information (i.e., unusual circumstance - * but not necessarily fatal.) Example usage looks like: - * itkWarningMacro(<< "this is warning info" << this->SomeVariable); */ -#define otbWarningMacro(x) \ - { \ - if (itk::Object::GetGlobalWarningDisplay()) \ - { \ - std::ostringstream itkmsg; \ - itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \ - << this->GetNameOfClass() << " (" << this << "): " x \ - << "\n\n"; \ - itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \ - } \ - } -#define otbGenericWarningMacro(x) \ - { \ - if (itk::Object::GetGlobalWarningDisplay()) \ - { \ - std::ostringstream itkmsg; \ - itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << ": " x <<"\n";\ - itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \ - } \ - } +#define otbDebugMacro(x) otbLogMacro(Debug,otbFileContext(otbClassContext(x))) +#define otbMsgDebugMacro(x) otbLogMacro(Debug,otbFileContext(x)) +#define otbGenericMsgDebugMacro(x) otbLogMacro(Debug,x) +#define otbMsgDevMacro(x) otbLogMacro(Info,otbFileContext(x)) +#define otbWarningMacro(x) otbLogMacro(Warning,otbFileContext(otbClassContext(x))) +#define otbGenericWarningMacro(x) otbLogMacro(Warning,otbFileContext(x)) + + + +// TODO: Address this macro as well +#define otbGenericMsgTestingMacro(x) \ + { \ + std::cout x << std::endl; \ + } + /** This macro is used to control condition. It use ONLY by the OTB developers * */