Mercurial > hg > orthanc
changeset 4017:c783f4f29390
log using emscripten
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Jun 2020 18:15:31 +0200 |
parents | c675d77b82ab |
children | 9d2d2c1afcec |
files | Core/Logging.cpp Core/Logging.h Resources/CMake/ZlibConfiguration.cmake |
diffstat | 3 files changed, 81 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/Logging.cpp Mon Jun 08 17:20:32 2020 +0200 +++ b/Core/Logging.cpp Mon Jun 08 18:15:31 2020 +0200 @@ -163,8 +163,8 @@ { namespace Logging { - static bool globalVerbose_ = false; - static bool globalTrace_ = false; + static bool infoEnabled_ = false; + static bool traceEnabled_ = false; #ifdef __EMSCRIPTEN__ static void ErrorLogFunc(const char* msg) @@ -208,12 +208,6 @@ } #endif /* __EMSCRIPTEN__ */ - InternalLogger::InternalLogger(LogLevel level, - const char* file /* ignored */, - int line /* ignored */) : - level_(level) - { - } InternalLogger::~InternalLogger() { @@ -222,25 +216,25 @@ switch (level_) { case LogLevel_ERROR: - globalErrorLogFunc(message.c_str()); + ErrorLogFunc(message.c_str()); break; case LogLevel_WARNING: - globalWarningLogFunc(message.c_str()); + WarningLogFunc(message.c_str()); break; case LogLevel_INFO: - if (globalVerbose_) + if (infoEnabled_) { - globalInfoLogFunc(message.c_str()); + InfoLogFunc(message.c_str()); // TODO: stone_console_info(message_.c_str()); } break; case LogLevel_TRACE: - if (globalTrace_) + if (traceEnabled_) { - globalTraceLogFunc(message.c_str()); + TraceLogFunc(message.c_str()); } break; @@ -249,7 +243,7 @@ std::stringstream ss; ss << "Unknown log level (" << level_ << ") for message: " << message; std::string s = ss.str(); - globalErrorLogFunc(s.c_str()); + ErrorLogFunc(s.c_str()); } } } @@ -276,22 +270,28 @@ void EnableInfoLevel(bool enabled) { - globalVerbose_ = enabled; + infoEnabled_ = enabled; + + if (!enabled) + { + // Also disable the "TRACE" level when info-level debugging is disabled + traceEnabled_ = false; + } } bool IsInfoLevelEnabled() { - return globalVerbose_; + return infoEnabled_; } void EnableTraceLevel(bool enabled) { - globalTrace_ = enabled; + traceEnabled_ = enabled; } bool IsTraceLevelEnabled() { - return globalTrace_; + return traceEnabled_; } void SetTargetFile(const std::string& path) @@ -760,8 +760,6 @@ break; case LogLevel_WARNING: - printf("[%s]\n", message.c_str()); - pluginContext_->InvokeService(pluginContext_, _OrthancPluginService_LogWarning, message.c_str()); break;
--- 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<>
--- a/Resources/CMake/ZlibConfiguration.cmake Mon Jun 08 17:20:32 2020 +0200 +++ b/Resources/CMake/ZlibConfiguration.cmake Mon Jun 08 18:15:31 2020 +0200 @@ -14,10 +14,6 @@ ${ZLIB_SOURCES_DIR}/compress.c ${ZLIB_SOURCES_DIR}/crc32.c ${ZLIB_SOURCES_DIR}/deflate.c - ${ZLIB_SOURCES_DIR}/gzclose.c - ${ZLIB_SOURCES_DIR}/gzlib.c - ${ZLIB_SOURCES_DIR}/gzread.c - ${ZLIB_SOURCES_DIR}/gzwrite.c ${ZLIB_SOURCES_DIR}/infback.c ${ZLIB_SOURCES_DIR}/inffast.c ${ZLIB_SOURCES_DIR}/inflate.c @@ -27,6 +23,16 @@ ${ZLIB_SOURCES_DIR}/zutil.c ) + if (NOT ORTHANC_SANDBOXED) + # The source files below require access to the filesystem + list(APPEND ZLIB_SOURCES + ${ZLIB_SOURCES_DIR}/gzlib.c + ${ZLIB_SOURCES_DIR}/gzclose.c + ${ZLIB_SOURCES_DIR}/gzread.c + ${ZLIB_SOURCES_DIR}/gzwrite.c + ) + endif() + source_group(ThirdParty\\zlib REGULAR_EXPRESSION ${ZLIB_SOURCES_DIR}/.*) if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" OR