Logging messages: qlogging.h
-
Hi!
Sometimes after the start program, I have an "ASSERT: bytes <= bufferSize in file tools qringbuffer.cpp line 113". I supposed that this is caused because of using qlogging mechanism in the multithread app.There is a messageHandler. Should I sync any qLog executions?
Thank you.
-
Hi,
Do you have a custom message handler ?
-
Well, installing a custom message handler usually means to you are using a custom message handler.
You have to handle the threading aspect in your custom handler.
-
@sitesv said in Logging messages: qlogging.h:
@SGaist , so, This messageHandler handles various types of log messages. So, I think this is a custom messages handler. Tomorrow I will post a code of handler.
Calling qInstallMessageHandler implies that you are using a custom message handler.
@sitesv said in Logging messages: qlogging.h:
@SGaist said in Logging messages: qlogging.h:
You have to handle the threading aspect in your custom handler
What do you mean?
That you have to use proper threading primitives to protect the resources you access in your handler.
-
@SGaist there is a handler code:
// Handler void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { // Creating writing-stream QTextStream out(m_logFile.data()); // Adding data/time out << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz "); // Detecting message type switch (type){ case QtInfoMsg: out << "INF "; break; case QtDebugMsg: out << "DBG "; break; case QtWarningMsg: out << "WRN "; break; case QtCriticalMsg: out << "CRT "; break; case QtFatalMsg: out << "FTL "; break; } // Adding message type and message out << context.category << ": " << msg << endl; out.flush(); }
There are no external resources... Only message as handler parameter.
-
-
@Christian-Ehrlicher , @SGaist
I have a quick question here: does Qt have any restriction on which threads can execute aQFile::method()
, compared to the thread where theQFile m_logFile
was created? Like, I know you can only doQSql...
operations in the thread which created the database connection, does that apply toQFile
, or are you free to write to that from any thread?? -
No, as long as you add a proper mutex.