1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLOGGING_P_H
5#define QLOGGING_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of a number of Qt sources files. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include "qlogging.h"
20#include "qloggingcategory.h"
21
22#if !defined(QT_BOOTSTRAPPED) && QT_CONFIG(regularexpression)
23# if __has_include(<cxxabi.h>) && QT_CONFIG(backtrace)
24# include <optional>
25# include "qvarlengtharray.h"
26# define QLOGGING_USE_EXECINFO_BACKTRACE
27# define QLOGGING_HAVE_BACKTRACE
28# elif QT_CONFIG(cxx23_stacktrace)
29# include <optional>
30# include <stacktrace>
31# define QLOGGING_USE_STD_BACKTRACE
32# define QLOGGING_HAVE_BACKTRACE
33# endif
34#endif // QT_BOOTSTRAPPED
35
36QT_BEGIN_NAMESPACE
37
38namespace QtPrivate {
39
40Q_CORE_EXPORT bool shouldLogToStderr();
41
42}
43
44class QInternalMessageLogContext : public QMessageLogContext
45{
46public:
47 static constexpr int DefaultBacktraceDepth = 32;
48
49#if defined(QLOGGING_USE_EXECINFO_BACKTRACE)
50 using BacktraceStorage = QVarLengthArray<void *, DefaultBacktraceDepth>;
51#elif defined(QLOGGING_USE_STD_BACKTRACE)
52 using BacktraceStorage = std::stacktrace;
53#else
54 using BacktraceStorage = bool; // dummy
55#endif
56
57 std::optional<BacktraceStorage> backtrace;
58
59 Q_ALWAYS_INLINE QInternalMessageLogContext(const QMessageLogContext &logContext)
60 {
61 int backtraceFrames = initFrom(logContext);
62 if (backtraceFrames)
63 populateBacktrace(frameCount: backtraceFrames);
64 }
65 QInternalMessageLogContext(const QMessageLogContext &logContext,
66 const QLoggingCategory &categoryOverride)
67 : QInternalMessageLogContext(logContext)
68 {
69 category = categoryOverride.categoryName();
70 }
71
72 int initFrom(const QMessageLogContext &logContext);
73 void populateBacktrace(int frameCount);
74};
75
76QT_END_NAMESPACE
77
78#endif // QLOGGING_P_H
79

source code of qtbase/src/corelib/global/qlogging_p.h