eVaf
ilogger.h
Go to the documentation of this file.
1 
20 #ifndef __COMMON_ILOGGER_H
21 # define __COMMON_ILOGGER_H
22 
23 #include "libcommon.h"
24 
25 #include <QObject>
26 #include <QString>
27 #include <QByteArray>
28 
29 
30 namespace eVaf {
31 namespace Common {
32 
43 typedef void (*FatalMsgHandler)(QString const & msg, QString const & source, QString const & where);
44 
51 {
52  Q_OBJECT
53 
54 public:
55 
59  enum Severity {
60  None = 0,
64  Info,
66  Count
67  };
68 
70  iLogger() : QObject() {}
71 
73  virtual ~iLogger() {}
74 
83  static iLogger * instance();
84 
88  virtual QString defaultSource() const = 0;
89 
99  virtual void setDefaultSource(QString const & source) = 0;
100 
105  virtual Severity severity(QString const & source = 0) = 0;
106 
116  virtual void setSeverity(Severity severity, QString const & source = 0) = 0;
117 
122  virtual uint maxSize(QString const & source = 0) = 0;
123 
136  virtual void setMaxSize(uint maxSize, QString const & source = 0) = 0;
137 
142  virtual uint maxCount(QString const & source = 0) = 0;
143 
158  virtual void setMaxCount(uint maxCount, QString const & source = 0) = 0;
159 
163  virtual Severity consoleSeverity() const = 0;
164 
172  virtual void setConsoleSeverity(Severity severity) = 0;
173 
193  virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0) = 0;
194 
201  virtual QString printf(char const * const fmt, ...) const
202 #ifdef Q_OS_LINUX
203  __attribute__((format(printf, 2, 3)))
204 #endif
205  = 0;
206 
217  virtual QString printable(QByteArray const & msg) const = 0;
218 
230  virtual FatalMsgHandler installFatalMsgHandler(FatalMsgHandler newHandler) = 0;
231 
232 
233 signals:
234 
246  void loggerEvent(Common::iLogger::Severity severity, QString const & text, QString const & source, QString const & where);
247 
248 };
249 
250 } // namespace eVaf::Common
251 } // namespace eVaf
252 
259 #define EVAF_FATAL_ERROR(...) \
260  do { \
261  eVaf::Common::iLogger::instance()->write( \
262  eVaf::Common::iLogger::Fatal, \
263  eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
264  0, \
265  eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
266  ); \
267  } while (0)
268 
275 #define EVAF_ERROR(...) \
276  do { \
277  eVaf::Common::iLogger::instance()->write( \
278  eVaf::Common::iLogger::Error, \
279  eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
280  0, \
281  eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
282  ); \
283  } while (0)
284 
291 #define EVAF_WARNING(...) \
292  do { \
293  eVaf::Common::iLogger::instance()->write( \
294  eVaf::Common::iLogger::Warning, \
295  eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
296  0, \
297  eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
298  ); \
299  } while (0)
300 
307 #define EVAF_INFO(...) \
308  do { \
309  eVaf::Common::iLogger::instance()->write( \
310  eVaf::Common::iLogger::Info, \
311  eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
312  0, \
313  eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
314  ); \
315  } while (0)
316 
323 #ifndef NDEBUG
324 # define EVAF_DEBUG(...) \
325  do { \
326  eVaf::Common::iLogger::instance()->write( \
327  eVaf::Common::iLogger::Debug, \
328  eVaf::Common::iLogger::instance()->printf(__VA_ARGS__), \
329  0, \
330  eVaf::Common::iLogger::instance()->printf("%s:%s:%d", __FILE__, __FUNCTION__, __LINE__) \
331  ); \
332  } while (0)
333 #else
334 # define EVAF_DEBUG(...) \
335  do { } while (0)
336 #endif
337 
338 #endif // ilogger.h
#define COMMON_EXPORT
Definition: libcommon.h:27
General information output by the application or modules.
Definition: ilogger.h:64
Fatal error that causes the application to stop functioning.
Definition: ilogger.h:61
virtual ~iLogger()
Empty virtual destructor.
Definition: ilogger.h:73
Expected issues in the software that will be solved automatically.
Definition: ilogger.h:63
Unexpected issues in the software that could be solved automatically.
Definition: ilogger.h:62
iLogger()
Interface constructor.
Definition: ilogger.h:70
Logger interface for eVaf modules and applications.
Definition: ilogger.h:50
Information for debugging purposes.
Definition: ilogger.h:65
Global eVaf namespace.
Definition: engine.h:37
void(* FatalMsgHandler)(QString const &msg, QString const &source, QString const &where)
Prototype for custom fatal message handler.
Definition: ilogger.h:43
Severity
Severity levels for messages indicating the meaning and seriousness of the message.
Definition: ilogger.h:59