eVaf
logger.h
Go to the documentation of this file.
1 
20 #ifndef __COMMON_LOGGER_H
21 #define __COMMON_LOGGER_H
22 
23 #include "ilogger.h"
24 
25 #include <QObject>
26 #include <QString>
27 #include <QHash>
28 #include <QExplicitlySharedDataPointer>
29 #include <QSharedData>
30 
31 class QThread;
32 
33 
34 namespace eVaf {
35 namespace Common {
36 namespace Internal {
37 
39 void defFatalMsgHandler(QString const & msg, QString const & source, QString const & where);
40 
46 class LoggerSource : public QSharedData
47 {
48 public:
49 
50  LoggerSource();
51 
52  LoggerSource(LoggerSource const & o);
53 
84  void init(QString const & source);
85 
86 
87 public: // Members (we don't bother adding getter/setter functions)
88 
90  QString name;
91 
94 
96  QString fileName;
97 
99  uint maxSize;
100 
102  uint maxCount;
103 
104 };
105 
112 class LoggerWorker : public QObject
113 {
114  Q_OBJECT
115 
116 public slots:
117 
126  void writeToLogFile(LoggerSource const & src, QString const & msg);
127 
128 };
129 
135 class Logger : public iLogger
136 {
137  Q_OBJECT
138 
139 public:
140 
141  Logger();
142 
143  virtual ~Logger();
144 
149  bool init();
150 
151  /*
152  iLogger interface
153  */
154 
155  virtual QString defaultSource() const;
156 
157  virtual void setDefaultSource(QString const & source);
158 
159  virtual iLogger::Severity severity(QString const & source = 0);
160 
161  virtual void setSeverity(iLogger::Severity severity, QString const & source = 0);
162 
163  virtual uint maxSize(QString const & source = 0);
164 
165  virtual void setMaxSize(uint maxSize, QString const & source = 0);
166 
167  virtual uint maxCount(QString const & source = 0);
168 
169  virtual void setMaxCount(uint maxCount, QString const & source = 0);
170 
171  virtual iLogger::Severity consoleSeverity() const { return mConsoleSeverity; }
172 
173  virtual void setConsoleSeverity(iLogger::Severity severity);
174 
175  virtual void write(Severity severity, QString const & msg, QString const & source = 0, QString const & where = 0);
176 
177  virtual QString printf(char const * const fmt, ...) const;
178 
179  virtual QString printable(QByteArray const & msg) const;
180 
181  virtual FatalMsgHandler installFatalMsgHandler(FatalMsgHandler newHandler);
182 
183 
184 signals:
185 
186  void writeToLogFile(LoggerSource const & src, QString const & msg);
187 
188 
189 private: // Members
190 
192  bool mReady;
193 
195  FatalMsgHandler mFatalMsgHandler;
196 
198  iLogger::Severity mConsoleSeverity;
199 
201  QExplicitlySharedDataPointer<LoggerSource> mDefaultSource;
202 
204  QHash<QString, QExplicitlySharedDataPointer<LoggerSource> > mSources;
205 
207  QThread * mThread;
208 
210  LoggerWorker * mWorker;
211 
212 
213 private: // Methods
214 
216  LoggerSource * getSource(QString const & name = QString());
217 
218 #ifdef Q_OS_WIN32
219  void setColor(short int c);
221 #endif
222 
223 };
224 
225 } // namespace eVaf::Common::Internal
226 } // namespace eVaf::Common
227 } // namespace eVaf
228 
229 #endif // logger.h
uint maxCount
Current maximum number of log files.
Definition: logger.h:102
iLogger::Severity severity
Current severity level.
Definition: logger.h:93
virtual iLogger::Severity consoleSeverity() const
Returns the current console severity level.
Definition: logger.h:171
Worker class for the logger.
Definition: logger.h:112
iLogger interface implementation.
Definition: logger.h:135
Logger interface for eVaf modules and applications.
Definition: ilogger.h:50
QString fileName
File name.
Definition: logger.h:96
Global eVaf namespace.
Definition: engine.h:37
uint maxSize
Current maximum size of log files.
Definition: logger.h:99
void defFatalMsgHandler(QString const &msg, QString const &source, QString const &where)
Default fatal error message handler.
void(* FatalMsgHandler)(QString const &msg, QString const &source, QString const &where)
Prototype for custom fatal message handler.
Definition: ilogger.h:43
QString name
Name of the source.
Definition: logger.h:90
Logger interface for eVaf.
void init(QString const &source)
Initializes the source.
Severity
Severity levels for messages indicating the meaning and seriousness of the message.
Definition: ilogger.h:59