[Interest] Logging best practice.

Charley Bay charleyb123 at gmail.com
Thu Dec 1 22:46:18 CET 2011


Stefano spaketh:

> >     is the state of the art use the debug functions (qDebug, qWarning,
> ...) in
> > conjunction with a custom message handler (qInstallMsgHandler) for log to
> > file system?
> > I found very simple and useful this approach, but I think that a log
> function
> > with message level is needed (i.e: qMessage() ) for a complete set of
> logging
> > levels.
> > Anyone else think that we need a new function with message log level?
>

Alex respondeth:

> I do. We are actually working on something based on qLog (
> http://docs.huihoo.com/qt/qtextended/4.4/debug-qtextended.html#qlog-categorized-logging
> )
>
> Initially we only started to look at it because we needed something in
> QtSensors but I definitely see this as a more generic thing. Besides
> porting it to Qt5 we are still investigating its usefulness as a generic
> Qt5 thing. We should soon have some preliminary results.
>
> So I guess, watch this space...


I agree that a good/strong logging infrastructure would be a good generic
thing.  However, beware of the convention in that link that does this:

qLog(Type) << "string=" << str << ", int=" << i;

That code is not re-entrant, because the "logging object" can be
intercepted by other threads entering that function.  We started out with
that syntax, and then had to change *all* our invocations for our
multi-threaded applications to make our functions re-entrant, like:

qlog(Type).logSomeMessage("some assembled message");

Just an FYI, our code *must* permit re-entrant code for logging.

--charley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20111201/ebbb779f/attachment.html>


More information about the Interest mailing list