Mercurial > hg > orthanc-stone
diff Resources/Orthanc/Core/Logging.cpp @ 40:7207a407bcd8
shared copyright with osimis
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 04 Jan 2017 16:37:42 +0100 |
parents | ff1e935768e7 |
children | 81e2651dca17 |
line wrap: on
line diff
--- a/Resources/Orthanc/Core/Logging.cpp Wed Dec 21 14:19:38 2016 +0100 +++ b/Resources/Orthanc/Core/Logging.cpp Wed Jan 04 16:37:42 2017 +0100 @@ -2,6 +2,7 @@ * Orthanc - A Lightweight, RESTful DICOM Store * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017 Osimis, Belgium * * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -73,7 +74,74 @@ } } -#else + +#elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1 + +/********************************************************* + * Logger compatible with the Orthanc plugin SDK + *********************************************************/ + +#include <boost/lexical_cast.hpp> + +namespace Orthanc +{ + namespace Logging + { + static OrthancPluginContext* context_ = NULL; + + void Initialize(OrthancPluginContext* context) + { + context_ = context_; + } + + InternalLogger::InternalLogger(const char* level, + const char* file /* ignored */, + int line /* ignored */) : + level_(level) + { + } + + InternalLogger::~InternalLogger() + { + if (context_ != NULL) + { + if (level_ == "ERROR") + { + OrthancPluginLogError(context_, message_.c_str()); + } + else if (level_ == "WARNING") + { + OrthancPluginLogWarning(context_, message_.c_str()); + } + else if (level_ == "INFO") + { + OrthancPluginLogInfo(context_, message_.c_str()); + } + } + } + + InternalLogger& InternalLogger::operator<< (const std::string& message) + { + message_ += message; + return *this; + } + + InternalLogger& InternalLogger::operator<< (const char* message) + { + message_ += std::string(message); + return *this; + } + + InternalLogger& InternalLogger::operator<< (int message) + { + message_ += boost::lexical_cast<std::string>(message); + return *this; + } + } +} + + +#else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */ /********************************************************* * Internal logger of Orthanc, that mimics some