diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2012-01-17 16:20:45 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-01 02:16:32 +0100 |
commit | d394ca7f27197cfbfc28eb9a08eb0db261dd9d3d (patch) | |
tree | e75e133531101682473f91f5feca6c88c3e38c6c /src/corelib/io | |
parent | ea783ff51f25af89b7219154d7be5de1fd138664 (diff) |
QtDebug: Include file, line, function information
Record the file, line, and function where a qDebug, qWarning, qCritical
or qFatal call happens, and make this information available in a custom
message handler.
The patch uses the C preprocessor to replace qDebug, qWarning, ... with
a line that also records the current file, line, and function. Custom
message handlers can access this information via a new QMessageLogContext
argument.
Change-Id: I0a9b89c1d137e41775932d3b1a35da4ebf12d18d
Reviewed-by: David Faure <faure@kde.org>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qdebug.h | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 5c38fcfbbb..c268660573 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QDebug { + friend class QMessageLogger; struct Stream { Stream(QIODevice *device) : ts(device), ref(1), type(QtDebugMsg), space(true), message_output(false) {} Stream(QString *string) : ts(string, QIODevice::WriteOnly), ref(1), type(QtDebugMsg), space(true), message_output(false) {} @@ -70,6 +71,7 @@ class Q_CORE_EXPORT QDebug QtMsgType type; bool space; bool message_output; + QMessageLogContext context; } *stream; public: inline QDebug(QIODevice *device) : stream(new Stream(device)) {} @@ -81,7 +83,9 @@ public: if (!--stream->ref) { if(stream->message_output) { QT_TRY { - qt_message_output(stream->type, stream->buffer.toLocal8Bit().data()); + qt_message_output(stream->type, + stream->context, + stream->buffer.toLocal8Bit().data()); } QT_CATCH(std::bad_alloc&) { /* We're out of memory - give up. */ } } delete stream; @@ -269,27 +273,6 @@ inline QDebug operator<<(QDebug debug, const QFlags<T> &flags) return debug.space(); } -#if !defined(QT_NO_DEBUG_OUTPUT) && !defined(QT_NO_DEBUG_STREAM) -Q_CORE_EXPORT_INLINE QDebug qDebug() { return QDebug(QtDebugMsg); } -#else -#undef qDebug -inline QNoDebug qDebug() { return QNoDebug(); } -#define qDebug QT_NO_QDEBUG_MACRO -#endif - -#if !defined(QT_NO_WARNING_OUTPUT) && !defined(QT_NO_DEBUG_STREAM) -Q_CORE_EXPORT_INLINE QDebug qWarning() { return QDebug(QtWarningMsg); } -#else -#undef qWarning -inline QNoDebug qWarning() { return QNoDebug(); } -#define qWarning QT_NO_QWARNING_MACRO -#endif - -#if !defined(QT_NO_DEBUG_STREAM) -Q_CORE_EXPORT_INLINE QDebug qCritical() { return QDebug(QtCriticalMsg); } -#endif - - QT_END_NAMESPACE QT_END_HEADER |