Mercurial > hg > orthanc
diff Core/Logging.h @ 4014:27628b0f6ada
merging logging code for plugins and files
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Jun 2020 17:03:25 +0200 |
parents | f0ee3f1db775 |
children | c783f4f29390 |
line wrap: on
line diff
--- a/Core/Logging.h Mon Jun 08 16:10:09 2020 +0200 +++ b/Core/Logging.h Mon Jun 08 17:03:25 2020 +0200 @@ -42,14 +42,6 @@ # error The macro ORTHANC_ENABLE_LOGGING must be defined #endif -#if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN) -# if ORTHANC_ENABLE_LOGGING == 1 -# error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined -# else -# define ORTHANC_ENABLE_LOGGING_PLUGIN 0 -# endif -#endif - #if !defined(ORTHANC_ENABLE_LOGGING_STDIO) # if ORTHANC_ENABLE_LOGGING == 1 # error The macro ORTHANC_ENABLE_LOGGING_STDIO must be defined @@ -58,7 +50,6 @@ # endif #endif -#include <boost/lexical_cast.hpp> namespace Orthanc { @@ -76,12 +67,10 @@ ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level); -#if ORTHANC_ENABLE_LOGGING_PLUGIN == 1 // "pluginContext" must be of type "OrthancPluginContext" - ORTHANC_PUBLIC void Initialize(void* pluginContext); -#else + ORTHANC_PUBLIC void InitializePluginContext(void* pluginContext); + ORTHANC_PUBLIC void Initialize(); -#endif ORTHANC_PUBLIC void Finalize(); @@ -120,21 +109,22 @@ #if ORTHANC_ENABLE_LOGGING != 1 -# define LOG(level) ::Orthanc::Logging::NullStream() -# define VLOG(level) ::Orthanc::Logging::NullStream() -#else -# define LOG(level) ::Orthanc::Logging::InternalLogger \ +#define LOG(level) ::Orthanc::Logging::NullStream() +#define VLOG(level) ::Orthanc::Logging::NullStream() + +#else /* ORTHANC_ENABLE_LOGGING == 1 */ + +#define LOG(level) ::Orthanc::Logging::InternalLogger \ (::Orthanc::Logging::LogLevel_ ## level, __FILE__, __LINE__) -# define VLOG(level) ::Orthanc::Logging::InternalLogger \ +#define VLOG(level) ::Orthanc::Logging::InternalLogger \ (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__) -#endif +#include "Compatibility.h" // For std::unique_ptr<> -#if (ORTHANC_ENABLE_LOGGING == 1 && \ - (ORTHANC_ENABLE_LOGGING_PLUGIN == 1 || \ - ORTHANC_ENABLE_LOGGING_STDIO == 1)) - +#include <boost/lexical_cast.hpp> #include <boost/noncopyable.hpp> +#include <boost/thread/mutex.hpp> +#include <sstream> namespace Orthanc { @@ -143,47 +133,10 @@ class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable { private: - LogLevel level_; - std::stringstream messageStream_; - - public: - InternalLogger(LogLevel level, - const char* file, - int line); - - ~InternalLogger(); - - template <typename T> - std::ostream& operator<< (const T& message) - { - messageStream_ << message; - return messageStream_; - } - }; - } -} - -#endif - - - - -#if (ORTHANC_ENABLE_LOGGING == 1 && \ - ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && \ - ORTHANC_ENABLE_LOGGING_STDIO == 0) - -#include <boost/thread/mutex.hpp> - -namespace Orthanc -{ - namespace Logging - { - class ORTHANC_PUBLIC InternalLogger - { - private: - boost::mutex::scoped_lock lock_; - NullStream null_; - std::ostream* stream_; + boost::mutex::scoped_lock lock_; + LogLevel level_; + std::unique_ptr<std::stringstream> pluginStream_; + std::ostream* stream_; public: InternalLogger(LogLevel level, @@ -211,7 +164,8 @@ * Orthanc::Logging::Reset() before the stream objects are * destroyed and the references become invalid. * - * This function must only be used by unit tests. + * This function must only be used by unit tests. It is ignored if + * InitializePluginContext() was called. **/ ORTHANC_PUBLIC void SetErrorWarnInfoLoggingStreams(std::ostream& errorStream, std::ostream& warningStream,