diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qlogging.cpp | 8 | ||||
-rw-r--r-- | src/corelib/global/qlogging.h | 29 | ||||
-rw-r--r-- | src/corelib/io/qloggingcategory.h | 7 |
3 files changed, 32 insertions, 12 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 575f484dd3..2a4f2dd4d6 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -174,6 +174,9 @@ Q_CORE_EXPORT bool qt_logging_to_console() The class provides information about the source code location a qDebug(), qWarning(), qCritical() or qFatal() message was generated. + \note By default, this information is recorded only in debug builds. You can overwrite + this explicitly by defining \c QT_MESSAGELOGCONTEXT or \c{QT_NO_MESSAGELOGCONTEXT}. + \sa QMessageLogger, QtMessageHandler, qInstallMessageHandler() */ @@ -185,8 +188,9 @@ Q_CORE_EXPORT bool qt_logging_to_console() QMessageLogger is used to generate messages for the Qt logging framework. Usually one uses it through qDebug(), qWarning(), qCritical, or qFatal() functions, - which are actually macros that expand to QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug() - et al. + which are actually macros: For example qDebug() expands to + QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug() + for debug builds, and QMessageLogger(0, 0, 0).debug() for release builds. One example of direct use is to forward errors that stem from a scripting language, e.g. QML: diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h index b952f999cb..f9bbf7fcce 100644 --- a/src/corelib/global/qlogging.h +++ b/src/corelib/global/qlogging.h @@ -124,13 +124,28 @@ private: QMessageLogContext context; }; -/* - qDebug, qWarning, qCritical, qFatal are redefined to automatically include context information - */ -#define qDebug QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug -#define qWarning QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).warning -#define qCritical QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).critical -#define qFatal QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).fatal +#if !defined(QT_MESSAGELOGCONTEXT) && !defined(QT_NO_MESSAGELOGCONTEXT) +# if defined(QT_NO_DEBUG) +# define QT_NO_MESSAGELOGCONTEXT +# else +# define QT_MESSAGELOGCONTEXT +# endif +#endif + +#ifdef QT_MESSAGELOGCONTEXT + #define QT_MESSAGELOG_FILE __FILE__ + #define QT_MESSAGELOG_LINE __LINE__ + #define QT_MESSAGELOG_FUNC Q_FUNC_INFO +#else + #define QT_MESSAGELOG_FILE 0 + #define QT_MESSAGELOG_LINE 0 + #define QT_MESSAGELOG_FUNC 0 +#endif + +#define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug +#define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning +#define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical +#define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug #define QT_NO_QWARNING_MACRO while (false) QMessageLogger().noDebug diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index cd3a7bf789..c7e242af08 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -110,15 +110,16 @@ private: static const QLoggingCategory category(__VA_ARGS__); \ return category; \ } + #define qCDebug(category, ...) \ for (bool qt_category_enabled = category().isDebugEnabled(); qt_category_enabled; qt_category_enabled = false) \ - QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).debug(__VA_ARGS__) + QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).debug(__VA_ARGS__) #define qCWarning(category, ...) \ for (bool qt_category_enabled = category().isWarningEnabled(); qt_category_enabled; qt_category_enabled = false) \ - QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).warning(__VA_ARGS__) + QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).warning(__VA_ARGS__) #define qCCritical(category, ...) \ for (bool qt_category_enabled = category().isCriticalEnabled(); qt_category_enabled; qt_category_enabled = false) \ - QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).critical(__VA_ARGS__) + QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).critical(__VA_ARGS__) #else // defined(Q_COMPILER_VARIADIC_MACROS) || defined(Q_MOC_RUN) |