Mercurial > hg > orthanc-dicomweb
changeset 58:cd7eaea06a42
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Aug 2015 14:13:45 +0200 |
parents | 1220d1cc186b |
children | 8546bb533b3b |
files | CMakeLists.txt Orthanc/Core/ImageFormats/ImageAccessor.cpp Orthanc/Core/Logging.h Orthanc/Core/PrecompiledHeaders.h Orthanc/Core/Toolbox.cpp Orthanc/Core/Toolbox.h Resources/SyncOrthancFolder.py |
diffstat | 7 files changed, 114 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Aug 03 18:13:28 2015 +0200 +++ b/CMakeLists.txt Tue Aug 04 14:13:45 2015 +0200 @@ -107,6 +107,7 @@ add_definitions( -DORTHANC_ENABLE_MD5=0 -DORTHANC_ENABLE_BASE64=0 + -DORTHANC_ENABLE_LOGGING=0 ) set(CORE_SOURCES
--- a/Orthanc/Core/ImageFormats/ImageAccessor.cpp Mon Aug 03 18:13:28 2015 +0200 +++ b/Orthanc/Core/ImageFormats/ImageAccessor.cpp Tue Aug 04 14:13:45 2015 +0200 @@ -33,6 +33,7 @@ #include "../PrecompiledHeaders.h" #include "ImageAccessor.h" +#include "../Logging.h" #include "../OrthancException.h" #include "../ChunkedBuffer.h" @@ -40,9 +41,6 @@ #include <cassert> #include <boost/lexical_cast.hpp> -#if HAVE_GOOGLE_LOG == 1 -#include <glog/logging.h> -#endif namespace Orthanc @@ -108,7 +106,7 @@ { if (readOnly_) { -#if HAVE_GOOGLE_LOG == 1 +#if ORTHANC_ENABLE_LOGGING == 1 LOG(ERROR) << "Trying to write on a read-only image"; #endif @@ -136,7 +134,7 @@ { if (readOnly_) { -#if HAVE_GOOGLE_LOG == 1 +#if ORTHANC_ENABLE_LOGGING == 1 LOG(ERROR) << "Trying to write on a read-only image"; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Orthanc/Core/Logging.h Tue Aug 04 14:13:45 2015 +0200 @@ -0,0 +1,93 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#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 <glog/logging.h> +#else +# include <iostream> +# include <boost/thread/mutex.hpp> +# define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) +# define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) +#endif + + +namespace Orthanc +{ + namespace Logging + { + void Initialize(); + + void Finalize(); + + void EnableInfoLevel(bool enabled); + + void EnableTraceLevel(bool enabled); + + void SetTargetFolder(const std::string& path); + + +#if ORTHANC_ENABLE_GOOGLE_LOG != 1 + class InternalLogger + { + private: + boost::mutex::scoped_lock lock_; + std::ostream* stream_; + + public: + InternalLogger(const char* level, + const char* file, + int line); + + ~InternalLogger() + { +#if defined(_WIN32) + *stream_ << "\r\n"; +#else + *stream_ << "\n"; +#endif + } + + std::ostream& operator<< (const std::string& message) + { + return (*stream_) << message; + } + }; +#endif + } +} + +#endif // ORTHANC_ENABLE_LOGGING
--- a/Orthanc/Core/PrecompiledHeaders.h Mon Aug 03 18:13:28 2015 +0200 +++ b/Orthanc/Core/PrecompiledHeaders.h Tue Aug 04 14:13:45 2015 +0200 @@ -46,7 +46,6 @@ #include <boost/thread.hpp> #include <boost/thread/shared_mutex.hpp> -#include <glog/logging.h> #include <json/value.h> #if ORTHANC_PUGIXML_ENABLED == 1 @@ -54,6 +53,7 @@ #endif #include "Enumerations.h" +#include "Logging.h" #include "OrthancException.h" #include "Toolbox.h" #include "Uuid.h"
--- a/Orthanc/Core/Toolbox.cpp Mon Aug 03 18:13:28 2015 +0200 +++ b/Orthanc/Core/Toolbox.cpp Tue Aug 04 14:13:45 2015 +0200 @@ -34,6 +34,7 @@ #include "Toolbox.h" #include "OrthancException.h" +#include "Logging.h" #include <string> #include <stdint.h> @@ -53,13 +54,9 @@ #include <boost/regex.hpp> #endif -#if HAVE_GOOGLE_LOG == 1 -#include <glog/logging.h> -#endif - #if defined(_WIN32) #include <windows.h> -#include <process.h> // For "_spawnvp()" +#include <process.h> // For "_spawnvp()" and "_getpid()" #else #include <unistd.h> // For "execvp()" #include <sys/wait.h> // For "waitpid()" @@ -1135,7 +1132,7 @@ if (pid == -1) { // Error in fork() -#if HAVE_GOOGLE_LOG == 1 +#if ORTHANC_ENABLE_LOGGING == 1 LOG(ERROR) << "Cannot fork a child process"; #endif @@ -1158,7 +1155,7 @@ if (status != 0) { -#if HAVE_GOOGLE_LOG == 1 +#if ORTHANC_ENABLE_LOGGING == 1 LOG(ERROR) << "System command failed with status code " << status; #endif @@ -1274,5 +1271,14 @@ } } + + int Toolbox::GetProcessId() + { +#if defined(_WIN32) + return static_cast<int>(_getpid()); +#else + return static_cast<int>(getpid()); +#endif + } }
--- a/Orthanc/Core/Toolbox.h Mon Aug 03 18:13:28 2015 +0200 +++ b/Orthanc/Core/Toolbox.h Tue Aug 04 14:13:45 2015 +0200 @@ -170,5 +170,7 @@ bool StartsWith(const std::string& str, const std::string& prefix); + + int GetProcessId(); } }
--- a/Resources/SyncOrthancFolder.py Mon Aug 03 18:13:28 2015 +0200 +++ b/Resources/SyncOrthancFolder.py Tue Aug 04 14:13:45 2015 +0200 @@ -26,6 +26,7 @@ 'Core/ImageFormats/ImageBuffer.h', 'Core/ImageFormats/PngReader.cpp', 'Core/ImageFormats/PngReader.h', + 'Core/Logging.h', 'Core/OrthancException.cpp', 'Core/OrthancException.h', 'Core/PrecompiledHeaders.h',