QtBase  v6.3.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
QLoggingCategory Class Reference

The QLoggingCategory class represents a category, or 'area' in the logging infrastructure. More...

#include <qloggingcategory.h>

Inheritance diagram for QLoggingCategory:
Inheritance graph
[legend]
Collaboration diagram for QLoggingCategory:
Collaboration graph
[legend]

Public Types

typedef void(* CategoryFilter) (QLoggingCategory *)
 

Public Member Functions

 QLoggingCategory (const char *category, QtMsgType severityLevel=QtDebugMsg)
 
 ~QLoggingCategory ()
 
bool isEnabled (QtMsgType type) const
 
void setEnabled (QtMsgType type, bool enable)
 
bool isDebugEnabled () const
 
bool isInfoEnabled () const
 
bool isWarningEnabled () const
 
bool isCriticalEnabled () const
 
const char * categoryName () const
 
QLoggingCategoryoperator() ()
 
const QLoggingCategoryoperator() () const
 

Static Public Member Functions

static QLoggingCategorydefaultCategory ()
 
static CategoryFilter installFilter (CategoryFilter)
 
static void setFilterRules (const QString &rules)
 

Detailed Description

The QLoggingCategory class represents a category, or 'area' in the logging infrastructure.

\inmodule QtCore

Since
5.2 \threadsafe

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.

To check whether a message type is enabled or not, use one of these methods: \l isDebugEnabled(), \l isInfoEnabled(), \l isWarningEnabled(), and \l isCriticalEnabled().

All objects are meant to be configured by a common registry, as described in \l{Configuring Categories}. Different objects can also represent the same category. Therefore, it's {not} recommended to export objects across module boundaries, to manipulate the objects directly, or to inherit from QLoggingCategory.

Definition at line 48 of file qloggingcategory.h.

Member Typedef Documentation

◆ CategoryFilter

QLoggingCategory::CategoryFilter

This is a typedef for a pointer to a function with the following signature:

A function with this signature can be installed with \l installFilter().

Definition at line 77 of file qloggingcategory.h.

Constructor & Destructor Documentation

◆ QLoggingCategory()

QLoggingCategory::QLoggingCategory ( const char *  category,
QtMsgType  enableForLevel = QtDebugMsg 
)
explicit

Constructs a QLoggingCategory object with the provided category name, and enables all messages with types at least as verbose as enableForLevel, which defaults to QtDebugMsg (which enables all categories).

If category is \nullptr, the category name "default" is used.

Note
category must be kept valid during the lifetime of this object. Using a string literal for it is the usual way to achieve this.
Since
5.4

Definition at line 218 of file qloggingcategory.cpp.

Here is the call graph for this function:

◆ ~QLoggingCategory()

QLoggingCategory::~QLoggingCategory ( )

Destroys a QLoggingCategory object.

Definition at line 241 of file qloggingcategory.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ categoryName()

const char * QLoggingCategory::categoryName ( ) const
inline

Returns the name of the category.

Definition at line 69 of file qloggingcategory.h.

Here is the caller graph for this function:

◆ defaultCategory()

QLoggingCategory * QLoggingCategory::defaultCategory ( )
static

Returns a pointer to the global category "default" that is used, for example, by qDebug(), qInfo(), qWarning(), qCritical(), or qFatal().

Note
The pointer returned may be null during destruction of static objects. Also, don't delete this pointer, as ownership of the category isn't transferred.

Definition at line 368 of file qloggingcategory.cpp.

◆ installFilter()

QLoggingCategory::CategoryFilter QLoggingCategory::installFilter ( QLoggingCategory::CategoryFilter  filter)
static

Installs a function 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().

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.

Example:

Alternatively, you can configure the default filter via \l setFilterRules().

Definition at line 401 of file qloggingcategory.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isCriticalEnabled()

bool QLoggingCategory::isCriticalEnabled ( ) const
inline

Returns true if critical messages should be shown for this category; false otherwise.

Note
The \l qCCritical() macro already does this check before executing any code. However, calling this method may be useful to avoid the expensive generation of data for debug output only.

Definition at line 67 of file qloggingcategory.h.

Here is the caller graph for this function:

◆ isDebugEnabled()

bool QLoggingCategory::isDebugEnabled ( ) const
inline

Returns true if debug messages should be shown for this category; false otherwise.

Note
The \l qCDebug() macro already does this check before running any code. However, calling this method may be useful to avoid the expensive generation of data for debug output only.

Definition at line 64 of file qloggingcategory.h.

Here is the caller graph for this function:

◆ isEnabled()

bool QLoggingCategory::isEnabled ( QtMsgType  msgtype) const

Returns true if a message of type msgtype for the category should be shown; false otherwise.

Definition at line 305 of file qloggingcategory.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isInfoEnabled()

bool QLoggingCategory::isInfoEnabled ( ) const
inline

Returns true if informational messages should be shown for this category; false otherwise.

Note
The \l qCInfo() macro already does this check before executing any code. However, calling this method may be useful to avoid the expensive generation of data for debug output only.
Since
5.5

Definition at line 65 of file qloggingcategory.h.

Here is the caller graph for this function:

◆ isWarningEnabled()

bool QLoggingCategory::isWarningEnabled ( ) const
inline

Returns true if warning messages should be shown for this category; false otherwise.

Note
The \l qCWarning() macro already does this check before executing any code. However, calling this method may be useful to avoid the expensive generation of data for debug output only.

Definition at line 66 of file qloggingcategory.h.

Here is the caller graph for this function:

◆ operator()() [1/2]

QLoggingCategory & QLoggingCategory::operator() ( )
inline

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.

Definition at line 72 of file qloggingcategory.h.

◆ operator()() [2/2]

const QLoggingCategory & QLoggingCategory::operator() ( ) const
inline

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.

Definition at line 73 of file qloggingcategory.h.

◆ setEnabled()

void QLoggingCategory::setEnabled ( QtMsgType  type,
bool  enable 
)

Changes the message type type for the category to enable.

This method is meant for use only from inside a filter installed with \l installFilter(). For an overview on how to configure categories globally, see \l {Configuring Categories}.

Note
QtFatalMsg cannot be changed; it will always remain true.

Definition at line 326 of file qloggingcategory.cpp.

Here is the caller graph for this function:

◆ setFilterRules()

void QLoggingCategory::setFilterRules ( const QString rules)
static

Configures which categories and message types should be enabled through a set of rules.

Example:

Note
The rules might be ignored if a custom category filter is installed with \l installFilter(), or if the user has defined the QT_LOGGING_CONF or the QT_LOGGING_RULES environment variable.

Definition at line 418 of file qloggingcategory.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ bools

AtomicBools QLoggingCategory::bools

Definition at line 103 of file qloggingcategory.h.

◆ enabled

QBasicAtomicInt QLoggingCategory::enabled

Definition at line 104 of file qloggingcategory.h.


The documentation for this class was generated from the following files: