Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohoslogger_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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 QOHOSLOGGER_H
5#define QOHOSLOGGER_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 purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qdebug.h>
19#include <QtCore/qloggingcategory.h>
20#include <QtCore/qthread.h>
21#include <cstdarg>
22#include <hilog/log.h>
23
24QT_BEGIN_NAMESPACE
25
26Q_CORE_EXPORT const QLoggingCategory &QtForOhos();
27
28#define qOhosDebug(category)
29 _Pragma("GCC diagnostic push")
30 _Pragma("GCC diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"")
31 qCDebug(category)
32 _Pragma("GCC diagnostic pop")
33
34#define qOhosWarning(category)
35 _Pragma("GCC diagnostic push")
36 _Pragma("GCC diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"")
37 qCWarning(category)
38 _Pragma("GCC diagnostic pop")
39
40#define qOhosCritical(category)
41 _Pragma("GCC diagnostic push")
42 _Pragma("GCC diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"")
43 qCCritical(category)
44 _Pragma("GCC diagnostic pop")
45
46#define qOhosFatal(category)
47 _Pragma("GCC diagnostic push")
48 _Pragma("GCC diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"")
49 qCFatal(category)
50 _Pragma("GCC diagnostic pop")
51
52Q_CORE_EXPORT void qOhosLogMessage(LogLevel logLevel, const char *tag, const char *message);
53
54Q_CORE_EXPORT Q_ATTRIBUTE_FORMAT_PRINTF(2, 0) void qOhosVPrintf(LogLevel logLevel, const char *format, std::va_list ap);
55
56Q_ATTRIBUTE_FORMAT_PRINTF(1, 2) inline void qOhosPrintfDebug(const char *format, ...)
57{
58 std::va_list ap;
59 va_start(ap, format);
60 qOhosVPrintf(LOG_DEBUG, format, ap);
61 va_end(ap);
62}
63
64Q_ATTRIBUTE_FORMAT_PRINTF(1, 2) inline void qOhosPrintfInfo(const char *format, ...)
65{
66 std::va_list ap;
67 va_start(ap, format);
68 qOhosVPrintf(LOG_INFO, format, ap);
69 va_end(ap);
70}
71
72Q_ATTRIBUTE_FORMAT_PRINTF(1, 2) inline void qOhosPrintfWarning(const char *format, ...)
73{
74 std::va_list ap;
75 va_start(ap, format);
76 qOhosVPrintf(LOG_WARN, format, ap);
77 va_end(ap);
78}
79
80Q_ATTRIBUTE_FORMAT_PRINTF(1, 2) inline void qOhosPrintfError(const char *format, ...)
81{
82 std::va_list ap;
83 va_start(ap, format);
84 qOhosVPrintf(LOG_ERROR, format, ap);
85 va_end(ap);
86}
87
88template<typename StringType>
90{
91 QCScopedDebug(StringType message):
92 m_message(message)
93 { qOhosDebug(QtForOhos) << "T:" << QThread::currentThreadId() << ", M:" << message << "begin";}
94
95 ~QCScopedDebug() { qOhosDebug(QtForOhos) << "T:" << QThread::currentThreadId() << ", M:" << m_message
96 << "end";}
97private:
98 StringType m_message;
99};
100
101template<typename StringType>
103{
104 QCScopedDebugJS(StringType message): m_message(message) {qOhosPrintfDebug("%s begin", message);}
105 ~QCScopedDebugJS() {qOhosPrintfDebug("%s end", m_message);}
106
107private:
108 StringType m_message;
109};
110
111template<typename StringType>
112auto make_QCScopedDebug(StringType&& message) -> QCScopedDebug<typename std::decay<StringType>::type> {
113 return {std::forward<StringType>(message)};
114}
115
116template<typename StringType>
117auto make_QCScopedDebugJS(StringType&& message) -> QCScopedDebugJS<typename std::decay<StringType>::type> {
118 return {std::forward<StringType>(message)};
119}
120
121#define DUMP(x) qOhosDebug(QtForOhos) << "T:" << QThread::currentThreadId() << #x << x;
122
123QT_END_NAMESPACE
124
125#endif // QOHOSLOGGER_H
void qOhosLogMessage(LogLevel logLevel, const char *tag, const char *message)
void qOhosVPrintf(LogLevel logLevel, const char *format, std::va_list ap)
QT_BEGIN_NAMESPACE Q_CORE_EXPORT const QLoggingCategory & QtForOhos()
Q_CORE_EXPORT Q_ATTRIBUTE_FORMAT_PRINTF(2, 0) void qOhosVPrintf(LogLevel logLevel
#define qOhosDebug(category)
Q_CORE_EXPORT const char * format
Q_CORE_EXPORT const char std::va_list ap
QCScopedDebugJS(StringType message)
QCScopedDebug(StringType message)