diff --git a/Code/Core/include/mapLogbook.h b/Code/Core/include/mapLogbook.h index deb54b5..41b6e5f 100644 --- a/Code/Core/include/mapLogbook.h +++ b/Code/Core/include/mapLogbook.h @@ -1,207 +1,207 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_LOGBOOK_H #define __MAP_LOGBOOK_H #include "itkLoggerBase.h" #include "itkLoggerOutput.h" #include #include "mapXMLLogger.h" #include "mapString.h" #include "mapSyncObject.h" #include "mapMacros.h" #include "mapMAPCoreExports.h" namespace map { namespace core { //forward declarations class LogbookImplementation; /*! @class Logbook * @brief Helper class for centralized logging. * * This class offers a logger as singeltons and a centralized access to its * logging functionality. This class is used within MatchPoint for default logging purposes. By * default the logging will be saved in a xml file (matchpoint.log in the current working directory). * The file may be changed any time, also you may add additional outputs. You can also deactivate the * default file output by setting the default log output file to an empty string. * @ingroup Logging */ class MAPCore_EXPORT Logbook { public: using OutputType = itk::LoggerBase::OutputType; - using PriorityLevelType = itk::LoggerBase::PriorityLevelType; + using PriorityLevelType = itk::LoggerBaseEnums::PriorityLevel; /*! Passes the content to normal and error logger. * @eguarantee strong*/ static void write(PriorityLevelType level, const String& content); /*! Helper methods: Passes the content to normal and error logger with priority level "debug". */ static void debug(const String& message) { - if (_currentPriorityLevel == itk::LoggerBase::DEBUG) + if (_currentPriorityLevel == itk::LoggerBaseEnums::PriorityLevel::DEBUG) { //only call the function and "risk" singelton checking and managing overhead //if the message will be logged anyway. - write(itk::LoggerBase::DEBUG, message); + write(itk::LoggerBaseEnums::PriorityLevel::DEBUG, message); } } /*! Helper methods: Passes the content to normal and error logger with priority level "info". */ static void info(const String& message) { - if (_currentPriorityLevel != itk::LoggerBase::CRITICAL) + if (_currentPriorityLevel != itk::LoggerBaseEnums::PriorityLevel::CRITICAL) { //only call the function and "risk" singelton checking and managing overhead //if the message will be logged anyway. - write(itk::LoggerBase::INFO, message); + write(itk::LoggerBaseEnums::PriorityLevel::INFO, message); } } /*! Helper methods: Passes the content to normal and error logger with priority level "warning". */ static void warning(const String& message) { - if (_currentPriorityLevel != itk::LoggerBase::CRITICAL) + if (_currentPriorityLevel != itk::LoggerBaseEnums::PriorityLevel::CRITICAL) { //only call the function and "risk" singelton checking and managing overhead //if the message will be logged anyway. - write(itk::LoggerBase::WARNING, message); + write(itk::LoggerBaseEnums::PriorityLevel::WARNING, message); } } /*! Helper methods: Passes the content to normal and error logger with priority level "critical". */ static void critical(const String& message) { - write(itk::LoggerBase::CRITICAL, message); + write(itk::LoggerBaseEnums::PriorityLevel::CRITICAL, message); } /*! Helper methods: Passes the content to normal and error logger with priority level "critical". */ static void error(const String& message) { - write(itk::LoggerBase::CRITICAL, message); + write(itk::LoggerBaseEnums::PriorityLevel::CRITICAL, message); } /*! Helper methods: Passes the content to normal and error logger with priority level "fatal". */ static void fatal(const String& message) { - write(itk::LoggerBase::FATAL, message); + write(itk::LoggerBaseEnums::PriorityLevel::FATAL, message); } /*! Flushes both loggers. */ static void flush(); /*! opens file stream to the new file. If it succeeds the the current default file stream will be closed and exchanged. * You can deactivate the default log out put by passing an empty string. * @eguarantee strong*/ static void setDefaultLogFileName(const String& fileName); /*! adds additional log outputs to the logbook. * @eguarantee strong * @pre pOuput must not be a NULL pointer.*/ static void addAdditionalLogOutput(OutputType* pOutput); /*! Attaches the central itk output window to the MatchPoint logging, by setting the OutputWindow to * a LoggerOutput using _spLogger.*/ static void attachITKOutputWindow(); /*!@eguarantee strong*/ static PriorityLevelType getLogbookMode(); - /*! Calls sets _currentPriorityLevel and _spLogger PriorityLevel to itk::LoggerBase::DEBUG. + /*! Calls sets _currentPriorityLevel and _spLogger PriorityLevel to itk::LoggerBaseEnums::PriorityLevel::DEBUG. Thus everything will be logged.*/ static void setLogbookToDebugMode(); - /*! Calls sets _currentPriorityLevel and _spLogger PriorityLevel to itk::LoggerBase::INFO. + /*! Calls sets _currentPriorityLevel and _spLogger PriorityLevel to itk::LoggerBaseEnums::PriorityLevel::INFO. Thus everything will be logged except of debug infos.*/ static void setLogbookToInfoMode(); - /*! Calls sets _currentPriorityLevel and _spLogger PriorityLevel to itk::LoggerBase::CRITICAL. + /*! Calls sets _currentPriorityLevel and _spLogger PriorityLevel to itk::LoggerBaseEnums::PriorityLevel::CRITICAL. Thus only criticals, errors and fatals will be logged.*/ static void setLogbookToCriticalMode(); /*! Calls sets _currentPriorityLevel and _spLogger PriorityLevel to the passed level. * @remark The logbook must not be in deprecated sync mode. The mode can only be changed * by the host or in standalone logbooks. * @pre The logbook must not be in deprecated sync mode.*/ static void setLogbookMode(PriorityLevelType level); /*! Returns true if there is an valid pointer to a logbook implementation. Returns false if the * logbook wasn't used yet and isn't initialized. * @eguarantee no fail*/ static bool isInitialized(); /** This function is called to add all information to pSyncObject * that are needed to performe a synchronisation of an other instance*/ static void getSynchronization(deployment::SyncObject& pSyncObject); /** This function is called to synchronize the instance with * the information of pSyncObject.*/ static void setSynchronization(const deployment::SyncObject& pSyncObject); /** This function is called to desynchronize the instance.*/ static void deSynchronize(); protected: /*! Creates the implementation singelton if it doesn't exist.*/ static void initializeLogger(); /*!changes the own logbook implmentation with the passed one. * The exchange is secured by the mutex. * @eguarantee strong * @pre pImpl must be a valid pointer to an implmentation. * @param [in,out] pImpl Pointer to the new implementation.*/ static void swapImplementations(LogbookImplementation* pImpl); using LogImplPointer = itk::SmartPointer; static LogImplPointer _spLoggerImpl; static std::mutex _testMutex; static std::mutex _initMutex; /*! Indicates of the logbook is on its "own" or synced with an other host * logbook */ static bool _syncedAsDedicated; static PriorityLevelType _currentPriorityLevel; static String _defaultFilename; private: Logbook() = delete; //purposely not implemented virtual ~Logbook() = delete; //purposely not implemented Logbook(const Logbook&) = delete; //purposely not implemented void operator=(const Logbook&) = delete; //purposely not implemented }; } // end namespace core } // end namespace map #include "mapLogbookMacros.h" #endif diff --git a/Code/Core/include/mapLogbookImplementation.h b/Code/Core/include/mapLogbookImplementation.h index c1aaf89..49d4d30 100644 --- a/Code/Core/include/mapLogbookImplementation.h +++ b/Code/Core/include/mapLogbookImplementation.h @@ -1,131 +1,131 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_LOGBOOK_IMPLEMENTATION_H #define __MAP_LOGBOOK_IMPLEMENTATION_H #include "itkLoggerOutput.h" #include "itkLoggerThreadWrapper.h" #include "itkStdStreamLogOutput.h" #include "mapXMLLogger.h" #include "mapString.h" #include namespace map { namespace core { //forward declaration class SharedFileStreamBase; /*! @class LogbookImplementation * @brief Helper class realizing the internel implemntation of the logbook. * * This class is used to abstract the implmentation of the logbook (PIMPL-Idiom) and * to realize a strong exception guarantee for the logbook. * @ingroup Logging */ class MAPCore_EXPORT LogbookImplementation : public itk::LightObject { public: using Self = LogbookImplementation; using Superclass = itk::LightObject; using Pointer = itk::SmartPointer; using ConstPointer = itk::SmartPointer; itkTypeMacro(LogbookImplementation, itk::LightObject); itkNewMacro(Self); using LoggerType = itk::LoggerThreadWrapper; using LoggerPointer = LoggerType::Pointer; using OutputType = LoggerType::OutputType; using OutputPointer = OutputType::Pointer; - using PriorityLevelType = LoggerType::PriorityLevelType; + using PriorityLevelType = itk::LoggerBaseEnums::PriorityLevel; /*! Returns a reference to the normal logger. @eguarantee no fail */ LoggerType& getLogger(); /*! Initializing the default output by opening a stream to the specified file. * If additional outputs exist (e.g. by cloning) they will also be setup. * @eguarantee basis*/ void initializeOutputs(const String& defaultOutputFileName); /*! adds additional log outputs to the logbook. * If the output has already been added to the logbook, * the method doesn't add it once again. * @eguarantee basis * @pre pOuput must be a valid pointer to OutputType.*/ void addAdditionalLogOutput(OutputType* pOutput); /*! clones the logbook implementation. * @return Smart pointer to the cloned implementation.*/ Pointer clone() const; /*! clones the logbook implementation and sets a new default out put. * @param [in] defaultOutputFileName Name of the new default output file, that should be opened. * @return Smart pointer to the cloned and modified implementation.*/ Pointer clone(const String& newDefaultOutputFileName) const; /*! Pointer to the itk output window != NULL if attachITKOutputWindow() was called. * needed by the logbook if the logger must be updated.*/ itk::LoggerOutput::Pointer _spItkOutputWindow; PriorityLevelType _currentPriorityLevel; protected: void initializeAdditionalOutputs(); LoggerPointer _spLogger; using OutputContainerType = std::set; OutputContainerType _additionalOutputs; using DefaultOutputType = itk::StdStreamLogOutput; using DefaultOutputPointer = DefaultOutputType::Pointer; DefaultOutputPointer _spDefaultOutput; using StreamPointer = itk::SmartPointer; StreamPointer _spDefaultStream; LogbookImplementation(); ~LogbookImplementation() override; private: LogbookImplementation(const LogbookImplementation&) = delete; //purposely not implemented void operator=(const LogbookImplementation&) = delete; //purposely not implemented }; } // end namespace core } // end namespace map #include "mapLogbookMacros.h" #endif diff --git a/Code/Core/include/mapXMLLogger.h b/Code/Core/include/mapXMLLogger.h index 6753f00..a24314a 100644 --- a/Code/Core/include/mapXMLLogger.h +++ b/Code/Core/include/mapXMLLogger.h @@ -1,90 +1,90 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #ifndef __MAP_XML_LOGGER_H #define __MAP_XML_LOGGER_H #include "itkLogger.h" #include "mapMacros.h" #include "mapMAPCoreExports.h" namespace map { namespace core { /*! @class XMLLogger * @brief Logger based on itk::Logger but generating XML outputs. * * Build xml log entries, regarding the following pattern:\n * \n * ...content...\n * * @remark The logger does not escape any special xml characters, * thus it is possible to inject further xml strutcures with the content * string. If you want to prevent such an injection you may convert the * string we the global function escapeSpecialXMLCharacters() befor you pass * the string to the logger. * @ingroup Logging */ class MAPCore_EXPORT XMLLogger: public itk::Logger { public: using Self = XMLLogger; using Superclass = Logger; using Pointer = itk::SmartPointer; using ConstPointer = itk::SmartPointer; /** Run-time type information (and related methods). */ itkTypeMacro(XMLLogger, itk::Logger); /** New macro for creation of through a Smart Pointer */ itkNewMacro(Self); /** Provides a xml formatted log entry */ - std::string BuildFormattedEntry(PriorityLevelType level, std::string const& content) override; + std::string BuildFormattedEntry(itk::LoggerBaseEnums::PriorityLevel level, std::string const& content) override; protected: /** Constructor */ XMLLogger() = default; /** Destructor */ ~XMLLogger() override = default; private: XMLLogger(const Self&) = delete; //purposely not implemented void operator=(const Self&) = delete; //purposely not implemented }; /*! Converts the passed content and "escapes" any special xml characters. * (e.g. "<" to "<"). * @return Converted string.*/ MAPCore_EXPORT std::string escapeSpecialXMLCharacters(std::string content); } // end namespace core } // end namespace map #endif diff --git a/Code/Core/source/mapLogbook.cpp b/Code/Core/source/mapLogbook.cpp index 1670500..47000ed 100644 --- a/Code/Core/source/mapLogbook.cpp +++ b/Code/Core/source/mapLogbook.cpp @@ -1,264 +1,264 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #include "mapLogbook.h" #include "mapLogbookImplementation.h" #include "mapSmartMetaProperty.h" #include "mapMetaProperty.h" #include #include namespace map { namespace core { Logbook::LogImplPointer Logbook::_spLoggerImpl = nullptr; std::mutex Logbook::_testMutex; std::mutex Logbook::_initMutex; - Logbook::PriorityLevelType Logbook::_currentPriorityLevel = itk::LoggerBase::INFO; + Logbook::PriorityLevelType Logbook::_currentPriorityLevel = itk::LoggerBaseEnums::PriorityLevel::INFO; bool Logbook::_syncedAsDedicated = false; String Logbook::_defaultFilename = "MatchPoint.log"; void Logbook:: write(PriorityLevelType level, const String& content) { if (_spLoggerImpl.IsNull()) { initializeLogger(); } _spLoggerImpl->getLogger().Write(level, content); }; void Logbook:: flush() { if (_spLoggerImpl.IsNotNull()) { _spLoggerImpl->getLogger().Flush(); } }; void Logbook:: setDefaultLogFileName(const String& fileName) { if (_spLoggerImpl.IsNotNull() && _defaultFilename != fileName) { //we need to exchange the implementation mapLogDebugStaticMacro( << "Attempt to change logbook default file. New file name: " << fileName); LogImplPointer spNewImpl = _spLoggerImpl->clone(fileName); //if we reached this point without exception the implementation //with the new file is open and established, thus swap the implmentations, //store the new default file and print the header. swapImplementations(spNewImpl); _defaultFilename = fileName; } else { _defaultFilename = fileName; } }; void Logbook:: addAdditionalLogOutput(OutputType* pOutput) { assert(pOutput); //must not be null if (_spLoggerImpl.IsNull()) { initializeLogger(); } mapLogDebugStaticMacro( << "Add output to logbook. Output: " << pOutput->GetNameOfClass()); LogImplPointer spNewImpl = _spLoggerImpl->clone(); spNewImpl->addAdditionalLogOutput(pOutput); swapImplementations(spNewImpl); }; void Logbook:: attachITKOutputWindow() { if (_spLoggerImpl.IsNull()) { initializeLogger(); } mapLogDebugStaticMacro( << "Attached itk ouput window to MatchPoint logbook"); std::lock_guard testHolder(_testMutex); std::lock_guard initHolder(_initMutex); if (_spLoggerImpl->_spItkOutputWindow.IsNull()) { itk::LoggerOutput::Pointer spNewLogger = itk::LoggerOutput::New(); itk::OutputWindow::SetInstance(spNewLogger); _spLoggerImpl->_spItkOutputWindow = spNewLogger; } _spLoggerImpl->_spItkOutputWindow->SetLogger(&(_spLoggerImpl->getLogger())); }; Logbook::PriorityLevelType Logbook:: getLogbookMode() { return _currentPriorityLevel; }; void Logbook:: setLogbookToDebugMode() { - setLogbookMode(itk::LoggerBase::DEBUG); + setLogbookMode(itk::LoggerBaseEnums::PriorityLevel::DEBUG); }; void Logbook:: setLogbookToInfoMode() { - setLogbookMode(itk::LoggerBase::INFO); + setLogbookMode(itk::LoggerBaseEnums::PriorityLevel::INFO); }; void Logbook:: setLogbookToCriticalMode() { - setLogbookMode(itk::LoggerBase::CRITICAL); + setLogbookMode(itk::LoggerBaseEnums::PriorityLevel::CRITICAL); }; void Logbook:: setLogbookMode(PriorityLevelType level) { if (_spLoggerImpl.IsNotNull()) { _spLoggerImpl->getLogger().SetPriorityLevel(level); } _currentPriorityLevel = level; }; bool Logbook:: isInitialized() { return _spLoggerImpl.IsNotNull(); }; void Logbook:: initializeLogger() { std::lock_guard testHolder(_testMutex); if (_spLoggerImpl.IsNull()) { { //mutex lock holder scope std::lock_guard initHolder(_initMutex); LogImplPointer spNewImpl = LogbookImplementation::New(); spNewImpl->initializeOutputs(_defaultFilename); _spLoggerImpl = spNewImpl; } // end of mutex lock holder scope } }; void Logbook:: swapImplementations(LogbookImplementation* pImpl) { assert(pImpl); //must not be null; _testMutex.lock(); _initMutex.lock(); _spLoggerImpl = pImpl; _initMutex.unlock(); _testMutex.unlock(); }; void Logbook:: getSynchronization(deployment::SyncObject& syncObject) { core::MetaPropertyBase::Pointer prop = core::SmartMetaProperty::New(_spLoggerImpl).GetPointer(); deployment::SyncObject::SyncPropertyMapType::value_type valuePair("Logbook_Impl", prop); syncObject._map.insert(valuePair); prop = core::MetaProperty::New(_currentPriorityLevel).GetPointer(); deployment::SyncObject::SyncPropertyMapType::value_type valuePair2("Logbook_Priority", prop); syncObject._map.insert(valuePair2); }; void Logbook:: setSynchronization(const deployment::SyncObject& syncObject) { LogImplPointer spNewLogger; if (syncObject.getProperty("Logbook_Impl", spNewLogger)) { //there is something to sync for the logbook... if (spNewLogger.GetPointer() != _spLoggerImpl) { _syncedAsDedicated = true; swapImplementations(spNewLogger); } syncObject.getProperty("Logbook_Priority", _currentPriorityLevel); } }; void Logbook:: deSynchronize() { mapLogInfoStaticMacro( << "Attempt to desync logbook."); LogImplPointer spNewImpl = _spLoggerImpl->clone(Logbook::_defaultFilename); //if we reached this point without exception the implementation //with the new file is open and established, thus swap the implmentations, //store the new default file and print the header. swapImplementations(spNewImpl); _syncedAsDedicated = false; }; } // end namespace core } // end namespace map diff --git a/Code/Core/source/mapLogbookImplementation.cpp b/Code/Core/source/mapLogbookImplementation.cpp index 3794fa5..0602b51 100644 --- a/Code/Core/source/mapLogbookImplementation.cpp +++ b/Code/Core/source/mapLogbookImplementation.cpp @@ -1,307 +1,307 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #include "mapLogbookImplementation.h" #include "mapExceptionObject.h" #include #include namespace map { namespace core { /*! @class SharedFileStreamBase * @brief Helper class realizing an std stream handled as a object with smart pointer * * Reason: Need for a shared_ptr to handle the same stream across different logbook * implementations. VS2005 has no std::tr1::shared_ptr. Thus uses the itk::SmartPointer * functionality. * @ingroup Logging */ class SharedFileStreamBase : public itk::LightObject { public: using Self = SharedFileStreamBase; using Superclass = itk::LightObject; using Pointer = itk::SmartPointer; using ConstPointer = itk::SmartPointer; itkTypeMacro(SharedFileStreamBase, itk::LightObject); virtual std::ostream& getStream() = 0; virtual const std::ostream& getStream() const = 0; protected: SharedFileStreamBase() = default; ~SharedFileStreamBase() override = default; private: SharedFileStreamBase(const SharedFileStreamBase&) = delete; //purposely not implemented void operator=(const SharedFileStreamBase&) = delete; //purposely not implemented }; /*! @class SharedDefaultLogFileStream * @brief Helper class realizing an dummy stream handled as a object with smart pointer * * Reason: Need for a shared_ptr to handle the same stream across different logbook * implementations. VS2005 has no std::tr1::shared_ptr. Thus uses the itk::SmartPointer * functionality. * @ingroup Logging */ class SharedNULLStream : public SharedFileStreamBase { public: using Self = SharedNULLStream; using Superclass = itk::LightObject; using Pointer = itk::SmartPointer; using ConstPointer = itk::SmartPointer; itkTypeMacro(SharedNULLStream, itk::LightObject); itkNewMacro(Self); std::ostream& getStream() override { return _stream; }; const std::ostream& getStream() const override { return _stream; }; protected: /*! Helper class that allows to generate a dummy os*/ class NullBuffer : public std::streambuf { public: int overflow(int c) override { return c; } }; NullBuffer _buffer; std::ostream _stream; SharedNULLStream() : _stream(&_buffer) { }; ~SharedNULLStream() override = default; private: SharedNULLStream(const SharedNULLStream&) = delete; //purposely not implemented void operator=(const SharedNULLStream&) = delete; //purposely not implemented }; /*! @class SharedDefaultLogFileStream * @brief Helper class realizing an std stream handled as a object with smart pointer * * Reason: Need for a shared_ptr to handle the same stream across different logbook * implementations. VS2005 has no std::tr1::shared_ptr. Thus uses the itk::SmartPointer * functionality. * @ingroup Logging */ class SharedDefaultLogFileStream : public SharedFileStreamBase { public: using Self = SharedDefaultLogFileStream; using Superclass = SharedFileStreamBase; using Pointer = itk::SmartPointer; using ConstPointer = itk::SmartPointer; itkTypeMacro(SharedDefaultLogFileStream, SharedFileStreamBase); itkNewMacro(Self); std::ostream& getStream() override { return _stream; }; const std::ostream& getStream() const override { return _stream; }; std::ofstream& getOFStream() { return _stream; }; const std::ofstream& getOFStream() const { return _stream; }; protected: std::ofstream _stream; SharedDefaultLogFileStream() = default; ~SharedDefaultLogFileStream() override = default; private: SharedDefaultLogFileStream(const SharedDefaultLogFileStream&) = delete; //purposely not implemented void operator=(const SharedDefaultLogFileStream&) = delete; //purposely not implemented }; //************************************************************************************************* //******************** class LogbookImplementation ********************************************** //************************************************************************************************* LogbookImplementation::LoggerType& LogbookImplementation:: getLogger() { return *(_spLogger.GetPointer()); }; void LogbookImplementation:: initializeOutputs(const String& defaultOutputFileName) { if (!defaultOutputFileName.empty()) { SharedDefaultLogFileStream::Pointer spNewStream = SharedDefaultLogFileStream::New(); spNewStream->getOFStream().open(defaultOutputFileName.c_str(), std::ios::out | std::ios::app); if (!(spNewStream->getOFStream().is_open())) { mapLogbookCheckDefaultExceptionMacro(<< "Error: cannot open specified file as default logbook output file. Filename: " << defaultOutputFileName); } _spDefaultStream = spNewStream; _spDefaultOutput->SetStream(_spDefaultStream->getStream()); } else { _spDefaultStream = SharedNULLStream::New(); _spDefaultOutput->SetStream(_spDefaultStream->getStream()); } initializeAdditionalOutputs(); if (_spItkOutputWindow.IsNotNull()) { _spItkOutputWindow->SetLogger(_spLogger); } }; void LogbookImplementation:: addAdditionalLogOutput(OutputType* pOutput) { assert(pOutput); //output may not be null. std::pair result; result = _additionalOutputs.insert(pOutput); if (result.second) { //this output isn't already in the set, //so it was added and shall also be added to the logger. _spLogger->AddLogOutput(pOutput); } }; LogbookImplementation::Pointer LogbookImplementation:: clone() const { Pointer spNewImpl = LogbookImplementation::New(); spNewImpl->_additionalOutputs = this->_additionalOutputs; spNewImpl->_spDefaultStream = this->_spDefaultStream; spNewImpl->_spDefaultOutput->SetStream(spNewImpl->_spDefaultStream->getStream()); spNewImpl->_spItkOutputWindow = this->_spItkOutputWindow; spNewImpl->_currentPriorityLevel = this->_currentPriorityLevel; spNewImpl->initializeAdditionalOutputs(); if (spNewImpl->_spItkOutputWindow.IsNotNull()) { spNewImpl->_spItkOutputWindow->SetLogger(spNewImpl->_spLogger); } return spNewImpl; }; LogbookImplementation::Pointer LogbookImplementation:: clone(const String& newDefaultOutputFileName) const { Pointer spNewImpl = LogbookImplementation::New(); spNewImpl->_additionalOutputs = this->_additionalOutputs; spNewImpl->_spItkOutputWindow = this->_spItkOutputWindow; spNewImpl->_currentPriorityLevel = this->_currentPriorityLevel; spNewImpl->initializeOutputs(newDefaultOutputFileName); return spNewImpl; }; void LogbookImplementation:: initializeAdditionalOutputs() { for (const auto & _additionalOutput : _additionalOutputs) { _spLogger->AddLogOutput(_additionalOutput); } }; LogbookImplementation:: LogbookImplementation() { _spItkOutputWindow = nullptr; - _currentPriorityLevel = itk::LoggerBase::INFO; + _currentPriorityLevel = itk::LoggerBaseEnums::PriorityLevel::INFO; _spLogger = LoggerType::New(); _spDefaultOutput = DefaultOutputType::New(); _spLogger->AddLogOutput(_spDefaultOutput); }; LogbookImplementation:: ~LogbookImplementation() { //ensure that the logger is deleted before the default output (because logger flushes on destruction) //if the logger isn't used by other parts of the program. _spLogger = nullptr; _spDefaultOutput = nullptr; }; } // end namespace core } // end namespace map \ No newline at end of file diff --git a/Code/Core/source/mapXMLLogger.cpp b/Code/Core/source/mapXMLLogger.cpp index 972aa37..c9bdeeb 100644 --- a/Code/Core/source/mapXMLLogger.cpp +++ b/Code/Core/source/mapXMLLogger.cpp @@ -1,61 +1,61 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL$ */ #include "mapXMLLogger.h" #include "mapSDXMLStrWriter.h" #include "itksys/SystemTools.hxx" namespace map { namespace core { std::string escapeSpecialXMLCharacters(std::string content) { return ::map::structuredData::encodeForXml(content); }; std::string XMLLogger:: - BuildFormattedEntry(PriorityLevelType level, std::string const& content) + BuildFormattedEntry(itk::LoggerBaseEnums::PriorityLevel level, std::string const& content) { std::string m_LevelString[] = { "MUSTFLUSH", "FATAL", "CRITICAL", "WARNING", "INFO", "DEBUG", "NOTSET" }; OStringStream s; s << "" << + s << " priorityLevel='" << m_LevelString[static_cast(level)] << "' logger='" << this->GetName() << "'>" << content << ""; return s.str(); }; } // end namespace core } // end namespace map \ No newline at end of file