QtBase  v6.3.1
qloggingcategory.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qloggingcategory.h"
41 #include "qloggingregistry_p.h"
42 
44 
45 const char qtDefaultCategoryName[] = "default";
46 
49 
50 #ifndef Q_ATOMIC_INT8_IS_SUPPORTED
51 static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
52 {
53  const int bit = 1 << shift;
54 
55  if (enable)
56  atomic->fetchAndOrRelaxed(bit);
57  else
58  atomic->fetchAndAndRelaxed(~bit);
59 }
60 #endif
61 
219  : d(nullptr),
220  name(nullptr)
221 {
222  init(category, enableForLevel);
223 }
224 
225 void QLoggingCategory::init(const char *category, QtMsgType severityLevel)
226 {
227  enabled.storeRelaxed(0x01010101); // enabledDebug = enabledWarning = enabledCritical = true;
228 
229  if (category)
230  name = category;
231  else
233 
235  reg->registerCategory(this, severityLevel);
236 }
237 
242 {
244  reg->unregisterCategory(this);
245 }
246 
306 {
307  switch (msgtype) {
308  case QtDebugMsg: return isDebugEnabled();
309  case QtInfoMsg: return isInfoEnabled();
310  case QtWarningMsg: return isWarningEnabled();
311  case QtCriticalMsg: return isCriticalEnabled();
312  case QtFatalMsg: return true;
313  }
314  return false;
315 }
316 
327 {
328  switch (type) {
329 #ifdef Q_ATOMIC_INT8_IS_SUPPORTED
330  case QtDebugMsg: bools.enabledDebug.storeRelaxed(enable); break;
331  case QtInfoMsg: bools.enabledInfo.storeRelaxed(enable); break;
332  case QtWarningMsg: bools.enabledWarning.storeRelaxed(enable); break;
333  case QtCriticalMsg: bools.enabledCritical.storeRelaxed(enable); break;
334 #else
335  case QtDebugMsg: setBoolLane(&enabled, enable, DebugShift); break;
336  case QtInfoMsg: setBoolLane(&enabled, enable, InfoShift); break;
337  case QtWarningMsg: setBoolLane(&enabled, enable, WarningShift); break;
338  case QtCriticalMsg: setBoolLane(&enabled, enable, CriticalShift); break;
339 #endif
340  case QtFatalMsg: break;
341  }
342 }
343 
369 {
370  return qtDefaultCategory();
371 }
372 
402 {
404 }
405 
419 {
421 }
422 
T fetchAndOrRelaxed(T valueToAdd) noexcept
Definition: qbasicatomic.h:167
T fetchAndAndRelaxed(T valueToAdd) noexcept
Definition: qbasicatomic.h:158
The QLoggingCategory class represents a category, or 'area' in the logging infrastructure.
static void setFilterRules(const QString &rules)
bool isInfoEnabled() const
static QLoggingCategory * defaultCategory()
void(* CategoryFilter)(QLoggingCategory *)
void setEnabled(QtMsgType type, bool enable)
QLoggingCategory(const char *category, QtMsgType severityLevel=QtDebugMsg)
static CategoryFilter installFilter(CategoryFilter)
bool isWarningEnabled() const
bool isEnabled(QtMsgType type) const
bool isCriticalEnabled() const
bool isDebugEnabled() const
static QLoggingRegistry * instance()
QLoggingCategory::CategoryFilter installFilter(QLoggingCategory::CategoryFilter filter)
void setApiRules(const QString &content)
The QString class provides a Unicode character string.
Definition: qstring.h:388
const QLoggingCategory & category()
[1]
QtMsgType
Definition: qlogging.h:60
@ QtCriticalMsg
Definition: qlogging.h:63
@ QtInfoMsg
Definition: qlogging.h:65
@ QtWarningMsg
Definition: qlogging.h:62
@ QtFatalMsg
Definition: qlogging.h:64
@ QtDebugMsg
Definition: qlogging.h:61
bool int shift
QT_BEGIN_NAMESPACE const char qtDefaultCategoryName[]
Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory,(qtDefaultCategoryName)) static void setBoolLane(QBasicAtomicInt *atomic
GLenum type
Definition: qopengl.h:270
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLboolean enable
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLuint name
QObject::connect nullptr