diff --git a/Modules/Core/Common/include/otbLogger.h b/Modules/Core/Common/include/otbLogger.h index ef420c7b2389a38af6be6d1f7cf19faaa4b7f1b5..0da8d382194a6815c31c19ccc21a3856a10fd383 100644 --- a/Modules/Core/Common/include/otbLogger.h +++ b/Modules/Core/Common/include/otbLogger.h @@ -59,8 +59,15 @@ public: // Overwrite this to provide custom formatting of log entries std::string BuildFormattedEntry(itk::Logger::PriorityLevelType, std::string const&) override; + /** Output logs about the RAM, caching and multi-threading settings */ void LogSetupInformation(); - + + /** Return true if the LogSetupInformation has already been called*/ + bool IsLogSetupInformationDone(); + + /** Set the flag m_LogSetupInfoDone to true */ + void LogSetupInformationDone(); + protected: Logger(); virtual ~Logger() ITK_OVERRIDE; @@ -71,6 +78,8 @@ private: static Pointer CreateInstance(); + bool m_LogSetupInfoDone; + }; // class Logger } // namespace otb diff --git a/Modules/Core/Common/src/otbLogger.cxx b/Modules/Core/Common/src/otbLogger.cxx index 51cc7adae9718e6671ea911be78daa04057c6174..6678aa16320e4498b1a93310abbf346479467795 100644 --- a/Modules/Core/Common/src/otbLogger.cxx +++ b/Modules/Core/Common/src/otbLogger.cxx @@ -58,6 +58,8 @@ Logger::Logger() this->SetTimeStampFormat(itk::LoggerBase::HUMANREADABLE); this->SetHumanReadableFormat("%Y-%m-%d %H:%M:%S"); + + m_LogSetupInfoDone = false; } Logger::~Logger() @@ -66,22 +68,29 @@ Logger::~Logger() void Logger::LogSetupInformation() { - std::ostringstream oss; - - oss<<"Default RAM limit for OTB is "<<otb::ConfigurationManager::GetMaxRAMHint()<<" MB"<<std::endl; - this->Info(oss.str()); - oss.str(""); - oss.clear(); - - oss<<"GDAL maximum cache size is "<<GDALGetCacheMax64()/(1024*1024)<<" MB"<<std::endl; - this->Info(oss.str()); - oss.str(""); - oss.clear(); - - oss<<"OTB will use at most "<<itk::MultiThreader::GetGlobalDefaultNumberOfThreads()<<" threads"<<std::endl; - this->Info(oss.str()); - oss.str(""); - oss.clear(); + if (! IsLogSetupInformationDone()) + { + std::ostringstream oss; + + oss<<"Default RAM limit for OTB is "<<otb::ConfigurationManager::GetMaxRAMHint()<<" MB"<<std::endl; + this->Info(oss.str()); + oss.str(""); + oss.clear(); + + oss<<"GDAL maximum cache size is "<<GDALGetCacheMax64()/(1024*1024)<<" MB"<<std::endl; + this->Info(oss.str()); + oss.str(""); + oss.clear(); + + oss<<"OTB will use at most "<<itk::MultiThreader::GetGlobalDefaultNumberOfThreads()<<" threads"<<std::endl; + this->Info(oss.str()); + oss.str(""); + oss.clear(); + + // only switch the flag for the singleton, so that other instances can call + // LogSetupInformation() several times + Instance()->LogSetupInformationDone(); + } } std::string Logger::BuildFormattedEntry(itk::Logger::PriorityLevelType level, std::string const & content) @@ -113,4 +122,14 @@ std::string Logger::BuildFormattedEntry(itk::Logger::PriorityLevelType level, st return s.str(); } +bool Logger::IsLogSetupInformationDone() +{ + return m_LogSetupInfoDone; +} + +void Logger::LogSetupInformationDone() +{ + m_LogSetupInfoDone = true; +} + } // namespace otb diff --git a/Modules/Core/Streaming/include/otbStreamingImageVirtualWriter.txx b/Modules/Core/Streaming/include/otbStreamingImageVirtualWriter.txx index ec0ae5ae6d760b11ca6238deb582174752bb7f21..7336993ed392de64e980c05a7178fdc4cbe66ca7 100644 --- a/Modules/Core/Streaming/include/otbStreamingImageVirtualWriter.txx +++ b/Modules/Core/Streaming/include/otbStreamingImageVirtualWriter.txx @@ -183,6 +183,8 @@ void StreamingImageVirtualWriter<TInputImage> ::GenerateData(void) { + otb::Logger::Instance()->LogSetupInformation(); + /** * Prepare all the outputs. This may deallocate previous bulk data. */ diff --git a/Modules/IO/ImageIO/include/otbImageFileWriter.txx b/Modules/IO/ImageIO/include/otbImageFileWriter.txx index 2ddaf018bf89a48109c86a902d2c6fa57c88089b..db7261ae70e0850f7ef305063da3a513c0158f49 100644 --- a/Modules/IO/ImageIO/include/otbImageFileWriter.txx +++ b/Modules/IO/ImageIO/include/otbImageFileWriter.txx @@ -281,6 +281,8 @@ ImageFileWriter<TInputImage> itkExceptionMacro(<< "No input to writer"); } + otb::Logger::Instance()->LogSetupInformation(); + /** Parse streaming modes */ if(m_FilenameHelper->StreamingTypeIsSet()) {