Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Logging messages: qlogging.h

Logging messages: qlogging.h

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 884 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sitesvS Offline
    sitesvS Offline
    sitesv
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you have a custom message handler ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      sitesvS 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Do you have a custom message handler ?

        sitesvS Offline
        sitesvS Offline
        sitesv
        wrote on last edited by
        #3

        @SGaist I don’t know.

        void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
        ...
        void main(...)
        {
        qInstallMessageHandler(messageHandler);
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          sitesvS 2 Replies Last reply
          1
          • SGaistS SGaist

            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.

            sitesvS Offline
            sitesvS Offline
            sitesv
            wrote on last edited by
            #5

            @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.

            SGaistS 1 Reply Last reply
            0
            • SGaistS SGaist

              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.

              sitesvS Offline
              sitesvS Offline
              sitesv
              wrote on last edited by sitesv
              #6

              @SGaist said in Logging messages: qlogging.h:

              You have to handle the threading aspect in your custom handler

              What do you mean?

              1 Reply Last reply
              0
              • sitesvS sitesv

                @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.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                sitesvS 1 Reply Last reply
                1
                • SGaistS SGaist

                  @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.

                  sitesvS Offline
                  sitesvS Offline
                  sitesv
                  wrote on last edited by
                  #8

                  @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 EhrlicherC 1 Reply Last reply
                  0
                  • sitesvS sitesv

                    @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 EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @sitesv Please read the answer from @SGaist :

                    That you have to use proper threading primitives to protect the resources you access in your handler.

                    So make sure your message handle can not be called from two threads simultaneously with e.g. a mutex.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher , @SGaist
                      I have a quick question here: does Qt have any restriction on which threads can execute a QFile::method(), compared to the thread where the QFile m_logFile was created? Like, I know you can only do QSql... operations in the thread which created the database connection, does that apply to QFile, or are you free to write to that from any thread??

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        No, as long as you add a proper mutex.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        2

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved