SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
logger.h
Go to the documentation of this file.
1 
6 #ifndef LOGGER_H
7 #define LOGGER_H
8 
9 #include <QtGlobal>
10 #include <QThreadStorage>
11 #include <QHash>
12 #include <QStringList>
13 #include <QMutex>
14 #include <QObject>
15 #include "logglobal.h"
16 #include "logmessage.h"
17 
18 #include "export.h"
19 
20 namespace qtwebapp {
21 
52 class LOGGING_API Logger : public QObject {
53  Q_OBJECT
54  Q_DISABLE_COPY(Logger)
55 public:
56 
62  Logger(QObject* parent);
63 
64 
74  Logger(const QString msgFormat="{timestamp} {type} {msg}", const QString timestampFormat="yyyy-MM-dd HH:mm:ss.zzz", const QtMsgType minLevel=QtDebugMsg, const int bufferSize=0, QObject* parent = 0);
75 
77  virtual ~Logger();
78 
89  virtual void log(const QtMsgType type, const QString& message, const QString &file="", const QString &function="", const int line=0);
90 
95  void installMsgHandler();
96 
100  void setMinMessageLevel(const QtMsgType& minMsgLevel) {
101  minLevel = minMsgLevel;
102  }
103 
107  QtMsgType getMinMessageLevel() const {
108  return minLevel;
109  }
110 
117  static void set(const QString& name, const QString& value);
118 
125  virtual void clear(const bool buffer=true, const bool variables=true);
126 
127 protected:
128 
130  QString msgFormat;
131 
134 
136  QtMsgType minLevel;
137 
140 
142  static QMutex mutex;
143 
148  virtual void write(const LogMessage* logMessage);
149 
150 private:
151 
154 
168  static void msgHandler(const QtMsgType type, const QString &message, const QString &file="", const QString &function="", const int line=0);
169 
170 
171 #if QT_VERSION >= 0x050000
172 
180  static void msgHandler5(const QtMsgType type, const QMessageLogContext& context, const QString &message);
181 
182 #else
183 
190  static void msgHandler4(const QtMsgType type, const char * message);
191 
192 #endif
193 
195  static QThreadStorage<QHash<QString,QString>*> logVars;
196 
198  QThreadStorage<QList<LogMessage*>*> buffers;
199 
200 };
201 
202 } // end of namespace
203 
204 #endif // LOGGER_H
QString timestampFormat
Definition: logger.h:133
QtMsgType minLevel
Definition: logger.h:136
Fixed< IntType, IntBits > log(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2295
static QThreadStorage< QHash< QString, QString > * > logVars
Definition: logger.h:195
QtMsgType getMinMessageLevel() const
Definition: logger.h:107
void setMinMessageLevel(const QtMsgType &minMsgLevel)
Definition: logger.h:100
QString msgFormat
Definition: logger.h:130
#define LOGGING_API
Definition: export.h:100
QThreadStorage< QList< LogMessage * > * > buffers
Definition: logger.h:198
static QMutex mutex
Definition: logger.h:142
static Logger * defaultLogger
Definition: logger.h:153