Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Which one qt logging framework should i choose?



  • 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?



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


Log in to reply