CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkLogService.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  Library: CTK
4 
5  Copyright (c) German Cancer Research Center,
6  Division of Medical and Biological Informatics
7 
8  Licensed under the Apache License, Version 2.0 (the "License");
9  you may not use this file except in compliance with the License.
10  You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14  Unless required by applicable law or agreed to in writing, software
15  distributed under the License is distributed on an "AS IS" BASIS,
16  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  See the License for the specific language governing permissions and
18  limitations under the License.
19 
20 =============================================================================*/
21 
22 
23 #ifndef CTKLOGSERVICE_H
24 #define CTKLOGSERVICE_H
25 
26 #include <QString>
27 
28 #include <stdexcept>
29 
30 #include "ctkLogStream.h"
31 #include <ctkServiceReference.h>
32 
33 
54 struct CTK_PLUGINFW_EXPORT ctkLogService
55 {
56 
57  virtual ~ctkLogService() {}
58 
59 
66  static const int LOG_ERROR; // = 1;
67 
75  static const int LOG_WARNING; // = 2;
76 
84  static const int LOG_INFO; // = 3;
85 
93  static const int LOG_DEBUG; // = 4;
94 
116  virtual void log(int level, const QString& message, const std::exception* exception = 0,
117  const char* file = 0, const char* function = 0, int line = -1) = 0;
118 
144  virtual void log(const ctkServiceReference& sr, int level, const QString& message,
145  const std::exception* exception = 0,
146  const char* file = 0, const char* function = 0, int line = -1) = 0;
147 
156  virtual int getLogLevel() const = 0;
157 
158 };
159 
160 Q_DECLARE_INTERFACE(ctkLogService, "org.commontk.service.log.LogService")
161 
162 
165 class CTK_PLUGINFW_EXPORT ctkLogStreamWithServiceRef : public ctkLogStream
166 {
167 public:
168 
170  int level, const std::exception* exc = 0,
171  const char* file = 0, const char* function = 0, int line = -1);
173 
175 
176 protected:
177 
179 };
180 
184 class CTK_PLUGINFW_EXPORT ctkNullLogStream : public ctkLogStream
185 {
186 public:
187 
190 
191 };
192 
198 #define CTK_DEBUG(logService) \
199  ((logService && logService->getLogLevel() >= ctkLogService::LOG_DEBUG) ? \
200  ctkLogStream(logService, ctkLogService::LOG_DEBUG, 0, __FILE__, __FUNCTION__, __LINE__) : \
201  ctkNullLogStream())
202 
203 #define CTK_DEBUG_EXC(logService, exc) \
204  ((logService && logService->getLogLevel() >= ctkLogService::LOG_DEBUG) ? \
205  ctkLogStream(logService, ctkLogService::LOG_DEBUG, exc, __FILE__, __FUNCTION__, __LINE__) : \
206  ctkNullLogStream())
207 
208 #define CTK_DEBUG_SR(logService, serviceRef) \
209  ((logService && logService->getLogLevel() >= ctkLogService::LOG_DEBUG) ? \
210  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_DEBUG, 0, __FILE__, __FUNCTION__, __LINE__)) : \
211  static_cast<ctkLogStream>(ctkNullLogStream()))
212 
213 #define CTK_DEBUG_SR_EXC(logService, serviceRef, exc) \
214  ((logService && logService->getLogLevel() >= ctkLogService::LOG_DEBUG) ? \
215  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_DEBUG, exc, __FILE__, __FUNCTION__, __LINE__)) : \
216  static_cast<ctkLogStream>(ctkNullLogStream()))
217 
218 #define CTK_INFO(logService) \
219  ((logService && logService->getLogLevel() >= ctkLogService::LOG_INFO) ? \
220  ctkLogStream(logService, ctkLogService::LOG_INFO, 0, __FILE__, __FUNCTION__, __LINE__) : \
221  ctkNullLogStream())
222 
223 #define CTK_INFO_EXC(logService, exc) \
224  ((logService && logService->getLogLevel() >= ctkLogService::LOG_INFO) ? \
225  ctkLogStream(logService, ctkLogService::LOG_INFO, exc, __FILE__, __FUNCTION__, __LINE__) : \
226  ctkNullLogStream())
227 
228 #define CTK_INFO_SR(logService, serviceRef) \
229  ((logService && logService->getLogLevel() >= ctkLogService::LOG_INFO) ? \
230  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_INFO, 0, __FILE__, __FUNCTION__, __LINE__)) : \
231  static_cast<ctkLogStream>(ctkNullLogStream()))
232 
233 #define CTK_INFO_SR_EXC(logService, serviceRef, exc) \
234  ((logService && logService->getLogLevel() >= ctkLogService::LOG_INFO) ? \
235  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_INFO, exc, __FILE__, __FUNCTION__, __LINE__)) : \
236  static_cast<ctkLogStream>(ctkNullLogStream()))
237 
238 #define CTK_WARN(logService) \
239  ((logService && logService->getLogLevel() >= ctkLogService::LOG_WARNING) ? \
240  ctkLogStream(logService, ctkLogService::LOG_WARNING, 0, __FILE__, __FUNCTION__, __LINE__) : \
241  ctkNullLogStream())
242 
243 #define CTK_WARN_EXC(logService, exc) \
244  ((logService && logService->getLogLevel() >= ctkLogService::LOG_WARNING) ? \
245  ctkLogStream(logService, ctkLogService::LOG_WARNING, exc, __FILE__, __FUNCTION__, __LINE__) : \
246  ctkNullLogStream())
247 
248 #define CTK_WARN_SR(logService, serviceRef) \
249  ((logService && logService->getLogLevel() >= ctkLogService::LOG_WARNING) ? \
250  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_WARNING, 0, __FILE__, __FUNCTION__, __LINE__)) : \
251  static_cast<ctkLogStream>(ctkNullLogStream()))
252 
253 #define CTK_WARN_SR_EXC(logService, serviceRef, exc) \
254  ((logService && logService->getLogLevel() >= ctkLogService::LOG_WARNING) ? \
255  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_WARNING, exc, __FILE__, __FUNCTION__, __LINE__)) : \
256  static_cast<ctkLogStream>(ctkNullLogStream()))
257 
258 #define CTK_ERROR(logService) \
259  ((logService && logService->getLogLevel() >= ctkLogService::LOG_ERROR) ? \
260  ctkLogStream(logService, ctkLogService::LOG_ERROR, 0, __FILE__, __FUNCTION__, __LINE__) : \
261  ctkNullLogStream())
262 
263 #define CTK_ERROR_EXC(logService, exc) \
264  ((logService && logService->getLogLevel() >= ctkLogService::LOG_ERROR) ? \
265  ctkLogStream(logService, ctkLogService::LOG_ERROR, exc, __FILE__, __FUNCTION__, __LINE__) : \
266  ctkNullLogStream())
267 
268 #define CTK_ERROR_SR(logService, serviceRef) \
269  ((logService && logService->getLogLevel() >= ctkLogService::LOG_ERRO) ? \
270  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_ERROR, 0, __FILE__, __FUNCTION__, __LINE__)) : \
271  static_cast<ctkLogStream>(ctkNullLogStream()))
272 
273 #define CTK_ERROR_SR_EXC(logService, serviceRef, exc) \
274  ((logService && logService->getLogLevel() >= ctkLogService::LOG_ERROR) ? \
275  static_cast<ctkLogStream>(ctkLogStreamWithServiceRef(logService, serviceRef, ctkLogService::LOG_ERROR, exc, __FILE__, __FUNCTION__, __LINE__)) : \
276  static_cast<ctkLogStream>(ctkNullLogStream()))
277 
280 #endif // CTKLOGSERVICE_H
ctkLogStreamWithServiceRef(const ctkLogStreamWithServiceRef &logStreamWithRef)
ctkServiceReference sr
ctkLogStreamWithServiceRef(ctkLogService *logService, const ctkServiceReference &sr, int level, const std::exception *exc=0, const char *file=0, const char *function=0, int line=-1)
virtual int getLogLevel() const =0
static const int LOG_ERROR
Definition: ctkLogService.h:66
virtual void log(const ctkServiceReference &sr, int level, const QString &message, const std::exception *exception=0, const char *file=0, const char *function=0, int line=-1)=0
static const int LOG_WARNING
Definition: ctkLogService.h:75
static const int LOG_INFO
Definition: ctkLogService.h:84
static const int LOG_DEBUG
Definition: ctkLogService.h:93
virtual void log(int level, const QString &message, const std::exception *exception=0, const char *file=0, const char *function=0, int line=-1)=0
virtual ~ctkLogService()
Definition: ctkLogService.h:57