Mercurial > hg > orthanc
changeset 2960:74a5a7fd6e0e
log flag to OrthancPluginSetHttpErrorDetails
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Dec 2018 18:56:39 +0100 |
parents | 7364415851ac |
children | 3ed449d0204d |
files | Core/OrthancException.h Plugins/Engine/OrthancPlugins.cpp Plugins/Include/orthanc/OrthancCPlugin.h |
diffstat | 3 files changed, 35 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/OrthancException.h Tue Dec 04 16:43:53 2018 +0100 +++ b/Core/OrthancException.h Tue Dec 04 18:56:39 2018 +0100 @@ -73,13 +73,17 @@ } OrthancException(ErrorCode errorCode, - const std::string& details) : + const std::string& details, + bool log = true) : errorCode_(errorCode), httpStatus_(ConvertErrorCodeToHttpStatus(errorCode)), details_(new std::string(details)) { #if ORTHANC_ENABLE_LOGGING == 1 - LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + if (log) + { + LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + } #endif } @@ -92,13 +96,17 @@ OrthancException(ErrorCode errorCode, HttpStatus httpStatus, - const std::string& details) : + const std::string& details, + bool log = true) : errorCode_(errorCode), httpStatus_(httpStatus), details_(new std::string(details)) { #if ORTHANC_ENABLE_LOGGING == 1 - LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + if (log) + { + LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details; + } #endif }
--- a/Plugins/Engine/OrthancPlugins.cpp Tue Dec 04 16:43:53 2018 +0100 +++ b/Plugins/Engine/OrthancPlugins.cpp Tue Dec 04 18:56:39 2018 +0100 @@ -324,10 +324,12 @@ private: HttpOutput& output_; std::auto_ptr<std::string> errorDetails_; + bool logDetails_; public: PluginHttpOutput(HttpOutput& output) : - output_(output) + output_(output), + logDetails_(false) { } @@ -336,9 +338,11 @@ return output_; } - void SetErrorDetails(const std::string& details) + void SetErrorDetails(const std::string& details, + bool logDetails) { errorDetails_.reset(new std::string(details)); + logDetails_ = logDetails; } bool HasErrorDetails() const @@ -346,6 +350,11 @@ return errorDetails_.get() != NULL; } + bool IsLogDetails() const + { + return logDetails_; + } + const std::string& GetErrorDetails() const { if (errorDetails_.get() == NULL) @@ -1069,7 +1078,8 @@ PImpl::PluginHttpOutput pluginOutput(output); - OrthancPluginErrorCode error = callback->Invoke(pimpl_->restCallbackMutex_, pluginOutput, flatUri, request); + OrthancPluginErrorCode error = callback->Invoke + (pimpl_->restCallbackMutex_, pluginOutput, flatUri, request); if (error == OrthancPluginErrorCode_Success && output.IsWritingMultipart()) @@ -1087,7 +1097,9 @@ if (pluginOutput.HasErrorDetails()) { - throw OrthancException(static_cast<ErrorCode>(error), pluginOutput.GetErrorDetails()); + throw OrthancException(static_cast<ErrorCode>(error), + pluginOutput.GetErrorDetails(), + pluginOutput.IsLogDetails()); } else { @@ -1389,8 +1401,9 @@ const _OrthancPluginSetHttpErrorDetails& p = *reinterpret_cast<const _OrthancPluginSetHttpErrorDetails*>(parameters); - PImpl::PluginHttpOutput* output = reinterpret_cast<PImpl::PluginHttpOutput*>(p.output); - output->SetErrorDetails(p.details); + PImpl::PluginHttpOutput* output = + reinterpret_cast<PImpl::PluginHttpOutput*>(p.output); + output->SetErrorDetails(p.details, p.log); }
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Tue Dec 04 16:43:53 2018 +0100 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Tue Dec 04 18:56:39 2018 +0100 @@ -6433,6 +6433,7 @@ { OrthancPluginRestOutput* output; const char* details; + uint8_t log; } _OrthancPluginSetHttpErrorDetails; /** @@ -6449,12 +6450,14 @@ * @param context The Orthanc plugin context, as received by OrthancPluginInitialize(). * @param output The HTTP connection to the client application. * @param details The details of the error message. + * @param log Whether to also write the detailed error to the Orthanc logs. * @ingroup REST **/ ORTHANC_PLUGIN_INLINE void OrthancPluginSetHttpErrorDetails( OrthancPluginContext* context, OrthancPluginRestOutput* output, - const char* details) + const char* details, + uint8_t log) { _OrthancPluginSetHttpErrorDetails params; params.output = output;