summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qloggingcategory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qloggingcategory.cpp')
-rw-r--r--src/corelib/io/qloggingcategory.cpp133
1 files changed, 99 insertions, 34 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 1a84f6359c..10763dd65a 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -9,18 +9,6 @@ QT_BEGIN_NAMESPACE
const char qtDefaultCategoryName[] = "default";
Q_GLOBAL_STATIC(QLoggingCategory, qtDefaultCategory, qtDefaultCategoryName)
-#ifndef Q_ATOMIC_INT8_IS_SUPPORTED
-static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
-{
- const int bit = 1 << shift;
-
- if (enable)
- atomic->fetchAndOrRelaxed(bit);
- else
- atomic->fetchAndAndRelaxed(~bit);
-}
-#endif
-
/*!
\class QLoggingCategory
\inmodule QtCore
@@ -32,7 +20,8 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
QLoggingCategory represents a certain logging category - identified by a
string - at runtime. A category can be configured to enable or disable
- logging of messages per message type.
+ logging of messages per message type. An exception are fatal messages,
+ which are always enabled.
To check whether a message type is enabled or not, use one of these methods:
\l isDebugEnabled(), \l isInfoEnabled(), \l isWarningEnabled(), and
@@ -51,6 +40,9 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\snippet qloggingcategory/main.cpp 1
+ There is also the Q_DECLARE_EXPORTED_LOGGING_CATEGORY() macro in
+ order to use a logging category across library boundaries.
+
Category names are free text; to configure categories using \l{Logging Rules}, their
names should follow this convention:
\list
@@ -88,7 +80,7 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
If no argument is passed, all messages are logged. Only Qt internal categories
which start with \c{qt} are handled differently: For these, only messages of type
- \c QtInfoMsg, \c QtWarningMsg, and \c QtCriticalMsg are logged by default.
+ \c QtInfoMsg, \c QtWarningMsg, \c QtCriticalMsg, and \c QFatalMsg are logged by default.
\note Logging categories are not affected by your C++ build configuration.
That is, whether messages are printed does not change depending on whether
@@ -288,17 +280,10 @@ bool QLoggingCategory::isEnabled(QtMsgType msgtype) const
void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
{
switch (type) {
-#ifdef Q_ATOMIC_INT8_IS_SUPPORTED
case QtDebugMsg: bools.enabledDebug.storeRelaxed(enable); break;
case QtInfoMsg: bools.enabledInfo.storeRelaxed(enable); break;
case QtWarningMsg: bools.enabledWarning.storeRelaxed(enable); break;
case QtCriticalMsg: bools.enabledCritical.storeRelaxed(enable); break;
-#else
- case QtDebugMsg: setBoolLane(&enabled, enable, DebugShift); break;
- case QtInfoMsg: setBoolLane(&enabled, enable, InfoShift); break;
- case QtWarningMsg: setBoolLane(&enabled, enable, WarningShift); break;
- case QtCriticalMsg: setBoolLane(&enabled, enable, CriticalShift); break;
-#endif
case QtFatalMsg: break;
}
}
@@ -308,7 +293,7 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
Returns the object itself. This allows for both: a QLoggingCategory variable, and
a factory method that returns a QLoggingCategory, to be used in \l qCDebug(),
- \l qCWarning(), or \l qCCritical() macros.
+ \l qCWarning(), \l qCCritical(), or \l qCFatal() macros.
*/
/*!
@@ -316,7 +301,7 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
Returns the object itself. This allows for both: a QLoggingCategory variable, and
a factory method that returns a QLoggingCategory, to be used in \l qCDebug(),
- \l qCWarning(), or \l qCCritical() macros.
+ \l qCWarning(), \l qCCritical(), or \l qCFatal() macros.
*/
/*!
@@ -343,13 +328,27 @@ QLoggingCategory *QLoggingCategory::defaultCategory()
*/
/*!
- Installs a function \a filter that is used to determine which categories
- and message types should be enabled. Returns a pointer to the previous
- installed filter.
-
- Every QLoggingCategory object created is passed to the filter, and the
- filter is free to change the respective category configuration with
- \l setEnabled().
+ \brief Take control of how logging categories are configured.
+
+ Installs a function \a filter that is used to determine which categories and
+ message types should be enabled. If \a filter is \nullptr, the default
+ message filter is reinstated. Returns a pointer to the previously-installed
+ filter.
+
+ Every QLoggingCategory object that already exists is passed to the filter
+ before \c installFilter() returns, and the filter is free to change each
+ category's configuration with \l setEnabled(). Any category it doesn't
+ change will retain the configuration it was given by the prior filter, so
+ the new filter does not need to delegate to the prior filter during this
+ initial pass over existing categories.
+
+ Any new categories added later will be passed to the new filter; a filter
+ that only aims to tweak the configuration of a select few categories, rather
+ than completely overriding the logging policy, can first pass the new
+ category to the prior filter, to give it its standard configuration, and
+ then tweak that as desired, if it is one of the categories of specific
+ interest to the filter. The code that installs the new filter can record the
+ return from \c installFilter() for the filter to use in such later calls.
When you define your filter, note that it can be called from different threads; but never
concurrently. This filter cannot call any static functions from QLoggingCategory.
@@ -357,6 +356,10 @@ QLoggingCategory *QLoggingCategory::defaultCategory()
Example:
\snippet qloggingcategory/main.cpp 21
+ installed (in \c{main()}, for example) by
+
+ \snippet qloggingcategory/main.cpp 22
+
Alternatively, you can configure the default filter via \l setFilterRules().
*/
QLoggingCategory::CategoryFilter
@@ -554,9 +557,49 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\sa qCritical()
*/
+
+/*!
+ \macro qCFatal(category)
+ \relates QLoggingCategory
+ \since 6.5
+
+ Returns an output stream for fatal messages in the logging category,
+ \a category.
+
+ If you are using the \b{default message handler}, the returned stream will abort
+ to create a core dump. On Windows, for debug builds, this function will
+ report a \c _CRT_ERROR enabling you to connect a debugger to the application.
+
+ Example:
+
+ \snippet qloggingcategory/main.cpp 16
+
+ \sa qFatal()
+*/
+
+/*!
+ \macro qCFatal(category, const char *message, ...)
+ \relates QLoggingCategory
+ \since 6.5
+
+ Logs a fatal message, \a message, in the logging category, \a category.
+ \a message may contain place holders to be replaced by additional arguments,
+ similar to the C printf() function.
+
+ Example:
+
+ \snippet qloggingcategory/main.cpp 17
+
+ If you are using the \b{default message handler}, this function will abort
+ to create a core dump. On Windows, for debug builds, this function will
+ report a \c _CRT_ERROR enabling you to connect a debugger to the application.
+
+ \sa qFatal()
+*/
+
/*!
\macro Q_DECLARE_LOGGING_CATEGORY(name)
- \sa Q_LOGGING_CATEGORY()
+ \sa Q_LOGGING_CATEGORY(), Q_DECLARE_EXPORTED_LOGGING_CATEGORY()
\relates QLoggingCategory
\since 5.2
@@ -567,8 +610,31 @@ void QLoggingCategory::setFilterRules(const QString &rules)
*/
/*!
+ \macro Q_DECLARE_EXPORTED_LOGGING_CATEGORY(name, EXPORT_MACRO)
+ \sa Q_LOGGING_CATEGORY(), Q_DECLARE_LOGGING_CATEGORY()
+ \relates QLoggingCategory
+ \since 6.5
+
+ Declares a logging category \a name. The macro can be used to declare
+ a common logging category shared in different parts of the program.
+
+ This works exactly like Q_DECLARE_LOGGING_CATEGORY(). However,
+ the logging category declared by this macro is additionally
+ qualified with \a EXPORT_MACRO. This is useful if the logging
+ category needs to be exported from a dynamic library.
+
+ For example:
+
+ \code
+ Q_DECLARE_EXPORTED_LOGGING_CATEGORY(lcCore, LIB_EXPORT_MACRO)
+ \endcode
+
+ This macro must be used outside of a class or function.
+*/
+
+/*!
\macro Q_LOGGING_CATEGORY(name, string)
- \sa Q_DECLARE_LOGGING_CATEGORY()
+ \sa Q_DECLARE_LOGGING_CATEGORY(), Q_DECLARE_EXPORTED_LOGGING_CATEGORY()
\relates QLoggingCategory
\since 5.2
@@ -596,8 +662,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
with a specific name. The implicitly-defined QLoggingCategory object is
created on first use, in a thread-safe manner.
- This macro must be used outside of a class or method. It is only defined
- if variadic macros are supported.
+ This macro must be used outside of a class or method.
*/
QT_END_NAMESPACE