10#include <QThreadStorage>
18namespace stefanfrings {
52class DECLSPEC
Logger :
public QObject {
76 Logger(
const QString msgFormat=
"{timestamp} {type} {msg}",
77 const QString timestampFormat=
"dd.MM.yyyy hh:mm:ss.zzz",
78 const QtMsgType minLevel=QtDebugMsg,
const int bufferSize=0,
79 QObject* parent =
nullptr);
94 virtual void log(
const QtMsgType type,
const QString& message,
const QString &file=
"",
95 const QString &function=
"",
const int line=0);
101 void installMsgHandler();
109 static void set(
const QString& name,
const QString& value);
117 virtual void clear(
const bool buffer=
true,
const bool variables=
true);
140 virtual void write(
const LogMessage* logMessage);
145 static Logger* defaultLogger;
160 static void msgHandler(
const QtMsgType type,
const QString &message,
const QString &file=
"",
161 const QString &function=
"",
const int line=0);
164#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
173 static void msgHandler5(
const QtMsgType type,
const QMessageLogContext& context,
const QString &message);
183 static void msgHandler4(
const QtMsgType type,
const char * message);
188 static QThreadStorage<QHash<QString,QString>*> logVars;
191 QThreadStorage<QList<LogMessage*>*> buffers;
Represents a single log message together with some data that are used to decorate the log message.
Decorates and writes log messages to the console, stderr.
QtMsgType minLevel
Minimum level of message types that are written out directly or trigger writing the buffered content.
QString timestampFormat
Format string of timestamps.
static QMutex mutex
Used to synchronize access of concurrent threads.
int bufferSize
Size of backtrace buffer, number of messages per thread.
QString msgFormat
Format string for message decoration.