Mercurial > hg > orthanc
diff Core/Logging.h @ 1495:fbe40117eb21
improve the performance of the internal logger
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 06 Aug 2015 18:19:32 +0200 |
parents | e460341872dc |
children | 46b2794042d6 |
line wrap: on
line diff
--- a/Core/Logging.h Wed Aug 05 10:07:53 2015 +0200 +++ b/Core/Logging.h Thu Aug 06 18:19:32 2015 +0200 @@ -35,12 +35,12 @@ #if ORTHANC_ENABLE_LOGGING == 1 #if ORTHANC_ENABLE_GOOGLE_LOG == 1 -# include <stdlib.h> // This fixes a problem in glog for recent releases of MinGW +# include <stdlib.h> // Including this fixes a problem in glog for recent releases of MinGW # include <glog/logging.h> #else # include <iostream> # include <boost/thread/mutex.hpp> -# define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) +# define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) #endif @@ -59,13 +59,22 @@ void SetTargetFolder(const std::string& path); +#if ORTHANC_ENABLE_GOOGLE_LOG != 1 + struct NullStream : public std::ostream + { + NullStream() : + std::ios(0), + std::ostream(0) + { + } + }; -#if ORTHANC_ENABLE_GOOGLE_LOG != 1 class InternalLogger { private: - boost::mutex::scoped_lock lock_; - std::ostream* stream_; + boost::mutex::scoped_lock lock_; + NullStream null_; + std::ostream* stream_; public: InternalLogger(const char* level, @@ -80,7 +89,7 @@ *stream_ << "\n"; #endif } - + std::ostream& operator<< (const std::string& message) { return (*stream_) << message;