comparison OrthancFramework/Sources/Logging.h @ 4269:c7bd2f21ccc3

new macro CLOG, and sharing more code between logging engines
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 02 Nov 2020 17:15:57 +0100
parents 0ae2ca210077
children 251a8b07fa37
comparison
equal deleted inserted replaced
4268:0ae2ca210077 4269:c7bd2f21ccc3
50 LogLevel_WARNING, 50 LogLevel_WARNING,
51 LogLevel_INFO, 51 LogLevel_INFO,
52 LogLevel_TRACE 52 LogLevel_TRACE
53 }; 53 };
54 54
55 enum TraceCategory 55 enum LogCategory
56 { 56 {
57 TraceCategory_GENERIC, 57 LogCategory_GENERIC,
58 TraceCategory_SQLITE, 58 LogCategory_SQLITE,
59 TraceCategory_DICOM 59 LogCategory_DICOM
60 }; 60 };
61 61
62 ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level); 62 ORTHANC_PUBLIC const char* EnumerationToString(LogLevel level);
63 63
64 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level); 64 ORTHANC_PUBLIC LogLevel StringToLogLevel(const char* level);
104 } 104 }
105 105
106 106
107 107
108 /** 108 /**
109 * NB: The macro "VLOG(unused)" is for backward compatibility with 109 * NB:
110 * Orthanc <= 1.8.0. 110 * - The "VLOG(unused)" macro is for backward compatibility with
111 * Orthanc <= 1.8.0.
112 * - The "CLOG()" macro stands for "category log" (new in Orthanc 1.8.1)
111 **/ 113 **/
112 114
115 #if defined(LOG)
116 # error The macro LOG cannot be defined beforehand
117 #endif
118
119 #if defined(VLOG)
120 # error The macro VLOG cannot be defined beforehand
121 #endif
122
123 #if defined(CLOG)
124 # error The macro CLOG cannot be defined beforehand
125 #endif
126
113 #if ORTHANC_ENABLE_LOGGING != 1 127 #if ORTHANC_ENABLE_LOGGING != 1
114 # define LOG(level) ::Orthanc::Logging::NullStream() 128 # define LOG(level) ::Orthanc::Logging::NullStream()
115 # define VLOG(unused) ::Orthanc::Logging::NullStream() 129 # define VLOG(unused) ::Orthanc::Logging::NullStream()
116 # define TLOG(category) ::Orthanc::Logging::NullStream() 130 # define CLOG(level, category) ::Orthanc::Logging::NullStream()
117 #else /* ORTHANC_ENABLE_LOGGING == 1 */ 131 #else /* ORTHANC_ENABLE_LOGGING == 1 */
118 # define LOG(level) ::Orthanc::Logging::InternalLogger \ 132 # define LOG(level) ::Orthanc::Logging::InternalLogger \
119 (::Orthanc::Logging::LogLevel_ ## level, \ 133 (::Orthanc::Logging::LogLevel_ ## level, \
120 ::Orthanc::Logging::TraceCategory_GENERIC, __FILE__, __LINE__) 134 ::Orthanc::Logging::LogCategory_GENERIC, __FILE__, __LINE__)
121 # define VLOG(unused) ::Orthanc::Logging::InternalLogger \ 135 # define VLOG(unused) ::Orthanc::Logging::InternalLogger \
122 (::Orthanc::Logging::LogLevel_TRACE, \ 136 (::Orthanc::Logging::LogLevel_TRACE, \
123 ::Orthanc::Logging::TraceCategory_GENERIC, __FILE__, __LINE__) 137 ::Orthanc::Logging::LogCategory_GENERIC, __FILE__, __LINE__)
124 # define TLOG(category) ::Orthanc::Logging::InternalLogger \ 138 # define CLOG(level, category) ::Orthanc::Logging::InternalLogger \
125 (::Orthanc::Logging::LogLevel_TRACE, \ 139 (::Orthanc::Logging::LogLevel_ ## level, \
126 ::Orthanc::Logging::TraceCategory_ ## category, __FILE__, __LINE__) 140 ::Orthanc::Logging::LogCategory_ ## category, __FILE__, __LINE__)
127 #endif 141 #endif
128 142
129 143
130 144
131 #if (ORTHANC_ENABLE_LOGGING == 1 && \ 145 #if (ORTHANC_ENABLE_LOGGING == 1 && \
142 { 156 {
143 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable 157 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable
144 { 158 {
145 private: 159 private:
146 LogLevel level_; 160 LogLevel level_;
147 TraceCategory category_; 161 LogCategory category_;
148 std::stringstream messageStream_; 162 std::stringstream messageStream_;
149 163
150 public: 164 public:
151 InternalLogger(LogLevel level, 165 InternalLogger(LogLevel level,
152 TraceCategory category, 166 LogCategory category,
153 const char* file /* ignored */, 167 const char* file /* ignored */,
154 int line /* ignored */) : 168 int line /* ignored */) :
155 level_(level), 169 level_(level),
156 category_(category) 170 category_(category)
157 { 171 {
189 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable 203 class ORTHANC_PUBLIC InternalLogger : public boost::noncopyable
190 { 204 {
191 private: 205 private:
192 boost::mutex::scoped_lock lock_; 206 boost::mutex::scoped_lock lock_;
193 LogLevel level_; 207 LogLevel level_;
194 TraceCategory category_;
195 std::unique_ptr<std::stringstream> pluginStream_; 208 std::unique_ptr<std::stringstream> pluginStream_;
196 std::ostream* stream_; 209 std::ostream* stream_;
197 210
198 public: 211 public:
199 InternalLogger(LogLevel level, 212 InternalLogger(LogLevel level,
200 TraceCategory category, 213 LogCategory category,
201 const char* file, 214 const char* file,
202 int line); 215 int line);
203 216
204 ~InternalLogger(); 217 ~InternalLogger();
205 218