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. Qt Thread-Safe Logging

Qt Thread-Safe Logging

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.9k 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.
  • N Offline
    N Offline
    nsourl
    wrote on last edited by nsourl
    #1

    Hi,

    I am currently working on a Qt project and I would like to use a logging mechanism for debugging and monitoring purposes.

    But after searching around for some answers in older posts in Qt Forums and Stack Overflow, I am a bit confused if I should use the buildin logging functions qDebug, qInfo and etc or I should use a third-party library. You can find below the links with some active Qt logging libraries:

    https://github.com/dept2/CuteLogger
    https://github.com/MEONMedical/Log4Qt
    https://github.com/francescmm/QLogger
    https://github.com/sfadiga/QLogger

    The program that I am currently working it's multithreaded, so the logging mechanism should be thread-safe, log async (if possible) and I would like to redirect our logs in the Linux syslog system. Also, I saw that CuteLogger is using a Singleton pattern and the global instance it's visible across all the project and you can easily use the log functions by accessing the global instance which it's considered as a plus if it can be available from any other library or buildin mechanism.

    So, which approach from listed below is the best fit for my case in your opinion? Any alternative solution or share your ideas with pros and cons for each approach?

    1. Use Qt buildin qInfo, qDebug and etc by using a custom message handler that redirects logging to syslog?
    2. Use a third-party library like CuteLogger and if it's supported to redirect logs in the Linux syslog?

    Thanks.

    aha_1980A 1 Reply Last reply
    0
    • N nsourl

      Hi,

      I am currently working on a Qt project and I would like to use a logging mechanism for debugging and monitoring purposes.

      But after searching around for some answers in older posts in Qt Forums and Stack Overflow, I am a bit confused if I should use the buildin logging functions qDebug, qInfo and etc or I should use a third-party library. You can find below the links with some active Qt logging libraries:

      https://github.com/dept2/CuteLogger
      https://github.com/MEONMedical/Log4Qt
      https://github.com/francescmm/QLogger
      https://github.com/sfadiga/QLogger

      The program that I am currently working it's multithreaded, so the logging mechanism should be thread-safe, log async (if possible) and I would like to redirect our logs in the Linux syslog system. Also, I saw that CuteLogger is using a Singleton pattern and the global instance it's visible across all the project and you can easily use the log functions by accessing the global instance which it's considered as a plus if it can be available from any other library or buildin mechanism.

      So, which approach from listed below is the best fit for my case in your opinion? Any alternative solution or share your ideas with pros and cons for each approach?

      1. Use Qt buildin qInfo, qDebug and etc by using a custom message handler that redirects logging to syslog?
      2. Use a third-party library like CuteLogger and if it's supported to redirect logs in the Linux syslog?

      Thanks.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi @nsourl,

      I'd go with Qt's categorized logging (i.e. qCDebug, see here as a starting point).

      Logging to syslog should be possible, if I read this blog entry.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      4
      • N Offline
        N Offline
        nsourl
        wrote on last edited by
        #3

        Hi @aha_1980 ,

        Thank you for your prompt reply and your help on my confusion.

        So, you suggest to use Qt's categorized logging and then use a message handler (I suppose by using QMutexLocker for multithreading) as described in the blog to redirect the logs to syslog. Is that right?

        It seems that now at least I have a clean and good approach for logging in my project.

        Although, has anyone from the Qt community tried or used the third-party libraries I mentioned above? Is there a specific reason that I should use on of them instead of proceeding with @aha_1980 approach? Any additional ideas, comments or suggestions are welcome too.

        Thanks.

        aha_1980A 1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I'm using Log4Qt since years without any real problems.

          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
          1
          • N nsourl

            Hi @aha_1980 ,

            Thank you for your prompt reply and your help on my confusion.

            So, you suggest to use Qt's categorized logging and then use a message handler (I suppose by using QMutexLocker for multithreading) as described in the blog to redirect the logs to syslog. Is that right?

            It seems that now at least I have a clean and good approach for logging in my project.

            Although, has anyone from the Qt community tried or used the third-party libraries I mentioned above? Is there a specific reason that I should use on of them instead of proceeding with @aha_1980 approach? Any additional ideas, comments or suggestions are welcome too.

            Thanks.

            aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @nsourl said in Qt Thread-Safe Logging:

            So, you suggest to use Qt's categorized logging and then use a message handler (I suppose by using QMutexLocker for multithreading) as described in the blog to redirect the logs to syslog. Is that right?

            No, as Qt already has integrated syslog capabilities. Please read my second link.

            Regards

            Qt has to stay free or it will die.

            1 Reply Last reply
            1

            • Login

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