comparison Core/Logging.h @ 2243:2dbfdafc2512

Logger compatible with the Orthanc plugin SDK
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Dec 2016 16:02:00 +0100
parents 595cf22b3e7e
children a3a65de1840f
comparison
equal deleted inserted replaced
2242:4e8e0ad2001c 2243:2dbfdafc2512
36 36
37 #if !defined(ORTHANC_ENABLE_LOGGING) 37 #if !defined(ORTHANC_ENABLE_LOGGING)
38 # error The macro ORTHANC_ENABLE_LOGGING must be defined 38 # error The macro ORTHANC_ENABLE_LOGGING must be defined
39 #endif 39 #endif
40 40
41 #if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN)
42 # if ORTHANC_ENABLE_LOGGING == 1
43 # error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined
44 # else
45 # define ORTHANC_ENABLE_LOGGING_PLUGIN 0
46 # endif
47 #endif
48
49 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
50 # include <orthanc/OrthancCPlugin.h>
51 #endif
52
41 namespace Orthanc 53 namespace Orthanc
42 { 54 {
43 namespace Logging 55 namespace Logging
44 { 56 {
57 #if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
58 void Initialize(OrthancPluginContext* context);
59 #else
45 void Initialize(); 60 void Initialize();
61 #endif
46 62
47 void Finalize(); 63 void Finalize();
48 64
49 void Reset(); 65 void Reset();
50 66
84 #if ORTHANC_ENABLE_LOGGING != 1 100 #if ORTHANC_ENABLE_LOGGING != 1
85 101
86 # define LOG(level) ::Orthanc::Logging::NullStream() 102 # define LOG(level) ::Orthanc::Logging::NullStream()
87 # define VLOG(level) ::Orthanc::Logging::NullStream() 103 # define VLOG(level) ::Orthanc::Logging::NullStream()
88 104
89 #else /* ORTHANC_ENABLE_LOGGING == 1 */ 105
106 #elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
107
108 # include <boost/noncopyable.hpp>
109 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__)
110 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
111
112 namespace Orthanc
113 {
114 namespace Logging
115 {
116 class InternalLogger : public boost::noncopyable
117 {
118 private:
119 std::string level_;
120 std::string message_;
121
122 public:
123 InternalLogger(const char* level,
124 const char* file,
125 int line);
126
127 ~InternalLogger();
128
129 InternalLogger& operator<< (const std::string& message);
130
131 InternalLogger& operator<< (const char* message);
132
133 InternalLogger& operator<< (int message);
134 };
135 }
136 }
137
138
139 #else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
90 140
91 # include <boost/thread/mutex.hpp> 141 # include <boost/thread/mutex.hpp>
92 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) 142 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__)
93 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__) 143 # define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
94 144