27 msgFormat(
"{timestamp} {type} {msg}"),
28 timestampFormat(
"yyyy-MM-dd HH:mm:ss.zzz"),
44 void Logger::msgHandler(
const QtMsgType type,
const QString &message,
const QString &file,
const QString &
function,
const int line)
46 static QMutex recursiveMutex(QMutex::Recursive);
47 static QMutex nonRecursiveMutex(QMutex::NonRecursive);
52 recursiveMutex.lock();
58 nonRecursiveMutex.unlock();
62 fputs(qPrintable(message),stderr);
72 recursiveMutex.unlock();
76 #if QT_VERSION >= 0x050000 77 void Logger::msgHandler5(
const QtMsgType type,
const QMessageLogContext &context,
const QString &message)
80 msgHandler(type,message,context.file,context.function,context.line);
94 #if QT_VERSION >= 0x050000 95 qInstallMessageHandler(0);
97 qInstallMsgHandler(0);
114 #if QT_VERSION >= 0x050000 115 qInstallMessageHandler(msgHandler5);
127 logVars.setLocalData(
new QHash<QString,QString>);
129 logVars.localData()->insert(name,value);
137 if (buffer &&
buffers.hasLocalData())
139 QList<LogMessage*>* buffer=
buffers.localData();
140 while (buffer && !buffer->isEmpty()) {
145 if (variables &&
logVars.hasLocalData())
153 void Logger::log(
const QtMsgType type,
const QString& message,
const QString &file,
const QString &
function,
const int line)
161 buffers.setLocalData(
new QList<LogMessage*>());
163 QList<LogMessage*>* buffer=
buffers.localData();
166 buffer->append(logMessage);
170 delete buffer->takeFirst();
174 while (!buffer->isEmpty())
virtual void log(const QtMsgType type, const QString &message, const QString &file="", const QString &function="", const int line=0)
static void msgHandler(const QtMsgType type, const QString &message, const QString &file="", const QString &function="", const int line=0)
virtual void write(const LogMessage *logMessage)
virtual void clear(const bool buffer=true, const bool variables=true)
static QThreadStorage< QHash< QString, QString > * > logVars
static void msgHandler4(const QtMsgType type, const char *message)
QString toString(const QString &msgFormat, const QString ×tampFormat) const
QThreadStorage< QList< LogMessage * > * > buffers
static void set(const QString &name, const QString &value)
static Logger * defaultLogger