comparison OrthancFramework/Sources/Logging.h @ 4273:0034f855c023

tuning log categories from command-line, and binary compat with orthanc framework 1.7.2
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Nov 2020 12:24:50 +0100
parents 1661544ea94d
children d7a50b7b8466
comparison
equal deleted inserted replaced
4272:1661544ea94d 4273:0034f855c023
95 bool enabled); 95 bool enabled);
96 96
97 ORTHANC_PUBLIC bool IsCategoryEnabled(LogLevel level, 97 ORTHANC_PUBLIC bool IsCategoryEnabled(LogLevel level,
98 LogCategory category); 98 LogCategory category);
99 99
100 ORTHANC_PUBLIC LogCategory StringToCategory(const std::string& category); 100 ORTHANC_PUBLIC bool LookupCategory(LogCategory& target,
101 const std::string& category);
102
103 ORTHANC_PUBLIC size_t GetCategoriesCount();
104
105 ORTHANC_PUBLIC const char* GetCategoryName(size_t i);
101 106
102 ORTHANC_PUBLIC void SetTargetFile(const std::string& path); 107 ORTHANC_PUBLIC void SetTargetFile(const std::string& path);
103 108
104 ORTHANC_PUBLIC void SetTargetFolder(const std::string& path); 109 ORTHANC_PUBLIC void SetTargetFolder(const std::string& path);
105 110
144 #if ORTHANC_ENABLE_LOGGING != 1 149 #if ORTHANC_ENABLE_LOGGING != 1
145 # define LOG(level) ::Orthanc::Logging::NullStream() 150 # define LOG(level) ::Orthanc::Logging::NullStream()
146 # define VLOG(unused) ::Orthanc::Logging::NullStream() 151 # define VLOG(unused) ::Orthanc::Logging::NullStream()
147 # define CLOG(level, category) ::Orthanc::Logging::NullStream() 152 # define CLOG(level, category) ::Orthanc::Logging::NullStream()
148 #else /* ORTHANC_ENABLE_LOGGING == 1 */ 153 #else /* ORTHANC_ENABLE_LOGGING == 1 */
149 # define LOG(level) ::Orthanc::Logging::InternalLogger \ 154 # define LOG(level) ::Orthanc::Logging::InternalLogger \
150 (::Orthanc::Logging::LogLevel_ ## level, \ 155 (::Orthanc::Logging::LogLevel_ ## level, \
151 ::Orthanc::Logging::LogCategory_GENERIC, __FILE__, __LINE__) 156 ::Orthanc::Logging::LogCategory_GENERIC, __FILE__, __LINE__)
152 # define VLOG(unused) ::Orthanc::Logging::InternalLogger \ 157 # define VLOG(unused) ::Orthanc::Logging::InternalLogger \
153 (::Orthanc::Logging::LogLevel_TRACE, \ 158 (::Orthanc::Logging::LogLevel_TRACE, \
154 ::Orthanc::Logging::LogCategory_GENERIC, __FILE__, __LINE__) 159 ::Orthanc::Logging::LogCategory_GENERIC, __FILE__, __LINE__)
155 # define CLOG(level, category) ::Orthanc::Logging::InternalLogger \ 160 # define CLOG(level, category) ::Orthanc::Logging::InternalLogger \
156 (::Orthanc::Logging::LogLevel_ ## level, \ 161 (::Orthanc::Logging::LogLevel_ ## level, \
157 ::Orthanc::Logging::LogCategory_ ## category, __FILE__, __LINE__) 162 ::Orthanc::Logging::LogCategory_ ## category, __FILE__, __LINE__)
158 #endif 163 #endif
186 level_(level), 191 level_(level),
187 category_(category) 192 category_(category)
188 { 193 {
189 } 194 }
190 195
196 // For backward binary compatibility with Orthanc Framework <= 1.8.0
197 InternalLogger(LogLevel level,
198 const char* file /* ignored */,
199 int line /* ignored */) :
200 level_(level),
201 category_(LogCategory_GENERIC)
202 {
203 }
204
191 ~InternalLogger(); 205 ~InternalLogger();
192 206
193 template <typename T> 207 template <typename T>
194 std::ostream& operator<< (const T& message) 208 std::ostream& operator<< (const T& message)
195 { 209 {
223 boost::mutex::scoped_lock lock_; 237 boost::mutex::scoped_lock lock_;
224 LogLevel level_; 238 LogLevel level_;
225 std::unique_ptr<std::stringstream> pluginStream_; 239 std::unique_ptr<std::stringstream> pluginStream_;
226 std::ostream* stream_; 240 std::ostream* stream_;
227 241
242 void Setup(LogCategory category,
243 const char* file,
244 int line);
245
228 public: 246 public:
229 InternalLogger(LogLevel level, 247 InternalLogger(LogLevel level,
230 LogCategory category, 248 LogCategory category,
249 const char* file,
250 int line);
251
252 // For backward binary compatibility with Orthanc Framework <= 1.8.0
253 InternalLogger(LogLevel level,
231 const char* file, 254 const char* file,
232 int line); 255 int line);
233 256
234 ~InternalLogger(); 257 ~InternalLogger();
235 258
237 std::ostream& operator<< (const T& message) 260 std::ostream& operator<< (const T& message)
238 { 261 {
239 return (*stream_) << boost::lexical_cast<std::string>(message); 262 return (*stream_) << boost::lexical_cast<std::string>(message);
240 } 263 }
241 }; 264 };
242
243 265
244 /** 266 /**
245 * Set custom logging streams for the error, warning and info 267 * Set custom logging streams for the error, warning and info
246 * logs. This function may not be called if a log file or folder 268 * logs. This function may not be called if a log file or folder
247 * has been set beforehand. All three references must be valid. 269 * has been set beforehand. All three references must be valid.