Mercurial > hg > orthanc
diff Core/Logging.h @ 4017:c783f4f29390
log using emscripten
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Jun 2020 18:15:31 +0200 |
parents | 27628b0f6ada |
children |
line wrap: on
line diff
--- a/Core/Logging.h Mon Jun 08 17:20:32 2020 +0200 +++ b/Core/Logging.h Mon Jun 08 18:15:31 2020 +0200 @@ -109,15 +109,60 @@ #if ORTHANC_ENABLE_LOGGING != 1 -#define LOG(level) ::Orthanc::Logging::NullStream() -#define VLOG(level) ::Orthanc::Logging::NullStream() +# 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 \ + (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__) +#endif -#else /* ORTHANC_ENABLE_LOGGING == 1 */ + + +#if (ORTHANC_ENABLE_LOGGING == 1 && \ + ORTHANC_ENABLE_LOGGING_STDIO == 1) +// This is notably for WebAssembly + +#include <boost/lexical_cast.hpp> +#include <boost/noncopyable.hpp> +#include <sstream> -#define LOG(level) ::Orthanc::Logging::InternalLogger \ - (::Orthanc::Logging::LogLevel_ ## level, __FILE__, __LINE__) -#define VLOG(level) ::Orthanc::Logging::InternalLogger \ - (::Orthanc::Logging::LogLevel_TRACE, __FILE__, __LINE__) +namespace Orthanc +{ + namespace Logging + { + class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable + { + private: + LogLevel level_; + std::stringstream messageStream_; + + public: + InternalLogger(LogLevel level, + const char* file /* ignored */, + int line /* ignored */) : + level_(level) + { + } + + ~InternalLogger(); + + template <typename T> + std::ostream& operator<< (const T& message) + { + return messageStream_ << boost::lexical_cast<std::string>(message); + } + }; + } +} + +#endif + + + +#if (ORTHANC_ENABLE_LOGGING == 1 && \ + ORTHANC_ENABLE_LOGGING_STDIO == 0) #include "Compatibility.h" // For std::unique_ptr<>