[Development] Proposal: Changing the default output of qDebug and friends

David Faure faure at kde.org
Fri Jul 27 11:18:54 CEST 2012


I again saw qDebugs committed with Q_FUNC_INFO explicitely in them, which 
shows that yes, the default should be changed :-)

On Thursday 29 March 2012 17:02:38 Olivier Goffart wrote:
> On Thursday 29 March 2012 13:17:14 kai.koehne at nokia.com wrote:
> > For my original proposal I took inspiration from the KDE debug output.
> > Anyhow, I agree that the application name / pid just adds noise if you
> > launched your app yourself from the shell.
> > 
> > So, about "[%{type}] %{function} - %{message}" then?
> > 
> > Any other opinions? Olivier, do you think that's sensible?
> 
> Bikesheding topic :-)  but if you ask my opinion, I think the %{type} is a
> bit too much information.

The problem is, "debug" is useless, but "WARNING" is useful. This is what 
KDebug does (nothing for debug output, WARNING for warnings, and ERROR for 
errors).
But %{type_other_than_debug} becomes a bit cumbersome :-)

An alternative is to use colors (I plan on submitting that for Qt-5.1), KDebug 
makes the method name blue for debug, and red for warnings.

> My personal preference would be: "%{function}: %message"

Let's go for that.

Another issue: QT_MESSAGE_PATTERN only affects qDebug(), but not
QDebug(QIODevice*), because that one sets the bool message_output to false,
and just lets the QTextStream write the message "as is" into the device.
This doesn't look easily fixable though ?

What we do in KDebug, for logging to files, is a custom QIODevice which 
reimplements writeData() in order to write the line sent by the QTextStream 
(at destruction time). Shall I just call the exported-but-not-documented 
qMessageFormatString() there?

What I'm trying to say, in fact, is that I don't see a way to fix this without 
a custom iodevice, so QDebug(QIODevice*) should probably be documented as 
"doesn't support QT_MESSAGE_PATTERN, use qMessageFormatString if you want to 
format the string" ?

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. KDE Frameworks 5




More information about the Development mailing list