Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging facilities and Qt

Tags:

What logging facilities do you use whit Qt ?

Do you choose qDebug(), qWarning(), qCritical(), qFatal() methods, or maybe something like Log4cpp (Log4cplus etc.), or maybe some custom-maked code ?

like image 798
cybevnm Avatar asked Oct 09 '09 09:10

cybevnm


2 Answers

If you are just working in a single thread, qDebug and such work pretty well, or you can modify them somewhat by installing your own handler with qInstallMessageHandler in QT 5.0+, or qInstallMsgHandler in old versions.

Note: Older versions of qDebug() etc., where you used qInstallMsgHandler (now deprecated, e.g. http://doc.qt.io/archives/4.6/qtglobal.html#qDebug) were not thread-safe. If you use threads, they would crash/break badly. Internally it was using QTextStream, which was reentrant, but not thread-safe.

like image 182
DarrylC Avatar answered Oct 02 '22 23:10

DarrylC


Since Qt 5.2 supports categorized logging: http://qt-project.org/doc/qt-5/qloggingcategory.html . This allows you to split up your logging messages into a (hierarchy of) categories, and fine tune which is logged, and what not.

like image 31
kkoehne Avatar answered Oct 02 '22 22:10

kkoehne