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. Which one qt logging framework should i choose?
Forum Updated to NodeBB v4.3 + New Features

Which one qt logging framework should i choose?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 4.1k Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    z7c9
    wrote on last edited by
    #1

    I find out seven logging frameworks about qt.

    1.log4qt:http://log4qt.sourceforge.net/
    2.log4qtfork:https://gitorious.org/log4qt
    3.cutelogger:https://gitorious.org/cutelogger
    4.qslog:https://bitbucket.org/razvanpetru/qt-components/wiki/QsLog
    5.qlogger:https://github.com/francescmm/qt-coding/tree/master/QLogger
    6.qtilities logging:http://jpnaude.github.io/Qtilities/page_logging.html
    7.qxtlogger:http://libqxt.bitbucket.org/doc/tip/qxtlogger.html

    now I wonder which one should I choose?

    BTW,qDebug and such are not "Thread-Safe"? ,So In Multi-Thread Enviroment qDebug and such are not suitable?

    1 Reply Last reply
    0
    • CAD_codingC Offline
      CAD_codingC Offline
      CAD_coding
      wrote on last edited by
      #2

      @QFile *logFile = NULL;
      QTextStream *logStream = NULL;
      QMutex *mutex = NULL;
      bool *debugMode = NULL;

      void myMessageOutput(QtMsgType type, const char *msg)
      {
      if(((logFile != NULL) && (debugMode != NULL)))
      {
      mutex->lock();
      switch (type)
      {
      case QtDebugMsg:
      if(!debugMode)
      {
      mutex->unlock();
      return;
      }
      logStream << msg;
      logStream->flush();
      break;
      case QtWarningMsg:
      logStream << "\n
      Warning **\n";
      logStream << msg;
      logStream << "\n
      Warning Complete *\n";
      logStream->flush();
      break;
      case QtCriticalMsg:
      logStream << "\n
      Critical **\n";
      logStream << msg;
      logStream << "\n
      Critical Complete *\n";
      logStream->flush();
      break;
      case QtFatalMsg:
      logStream << "\n
      Fatal **\n";
      logStream << msg;
      logStream << "\n
      Fatal Complete ***\n";
      logStream->flush();
      abort();
      }
      mutex->unlock();
      }
      }

      int main(int argc, char *argv[])
      {
      //mutex for qdebug()
      mutex = new QMutex();
      //transfers output from qDebug() to a log file
      qInstallMsgHandler(myMessageOutput);
      //variable storing whether to run in debug mode or not
      debugMode = new bool;
      //log == path of log file
      QFile *file = new QFile(log);
      logStream = new QTextStream(file);
      logFile = file;
      ...
      }@

      Hope this helps!
      It may not work exactly as you want. Just modify according to your needs.
      Some code might be missing.
      Also please delete the dynamic variables after application exists.

      1 Reply Last reply
      0

      • Login

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