Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/global/qlogging.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com> | - | ||||||||||||||||||||||||
5 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||||||||
6 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
9 | ** | - | ||||||||||||||||||||||||
10 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
11 | ** Commercial License Usage | - | ||||||||||||||||||||||||
12 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
13 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
14 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
15 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
16 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
17 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
18 | ** | - | ||||||||||||||||||||||||
19 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
20 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
21 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
22 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
23 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
24 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
25 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
26 | ** | - | ||||||||||||||||||||||||
27 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
28 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
29 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
30 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
31 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
32 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
33 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
34 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
35 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
36 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
37 | ** | - | ||||||||||||||||||||||||
38 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
39 | ** | - | ||||||||||||||||||||||||
40 | ****************************************************************************/ | - | ||||||||||||||||||||||||
41 | - | |||||||||||||||||||||||||
42 | #include "qlogging.h" | - | ||||||||||||||||||||||||
43 | #include "qlist.h" | - | ||||||||||||||||||||||||
44 | #include "qbytearray.h" | - | ||||||||||||||||||||||||
45 | #include "qstring.h" | - | ||||||||||||||||||||||||
46 | #include "qvarlengtharray.h" | - | ||||||||||||||||||||||||
47 | #include "qdebug.h" | - | ||||||||||||||||||||||||
48 | #include "qmutex.h" | - | ||||||||||||||||||||||||
49 | #include "qloggingcategory.h" | - | ||||||||||||||||||||||||
50 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
51 | #include "qelapsedtimer.h" | - | ||||||||||||||||||||||||
52 | #include "qdatetime.h" | - | ||||||||||||||||||||||||
53 | #include "qcoreapplication.h" | - | ||||||||||||||||||||||||
54 | #include "qthread.h" | - | ||||||||||||||||||||||||
55 | #include "private/qloggingregistry_p.h" | - | ||||||||||||||||||||||||
56 | #include "private/qcoreapplication_p.h" | - | ||||||||||||||||||||||||
57 | #include "private/qsimd_p.h" | - | ||||||||||||||||||||||||
58 | #endif | - | ||||||||||||||||||||||||
59 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
60 | #include <qt_windows.h> | - | ||||||||||||||||||||||||
61 | #endif | - | ||||||||||||||||||||||||
62 | #ifdef QT_USE_SLOG2 | - | ||||||||||||||||||||||||
63 | #include <slog2.h> | - | ||||||||||||||||||||||||
64 | #endif | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | #ifdef Q_OS_ANDROID | - | ||||||||||||||||||||||||
67 | #include <android/log.h> | - | ||||||||||||||||||||||||
68 | #endif | - | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | #if defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
71 | # define SD_JOURNAL_SUPPRESS_LOCATION | - | ||||||||||||||||||||||||
72 | # include <systemd/sd-journal.h> | - | ||||||||||||||||||||||||
73 | # include <syslog.h> | - | ||||||||||||||||||||||||
74 | #endif | - | ||||||||||||||||||||||||
75 | #if defined(QT_USE_SYSLOG) && !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
76 | # include <syslog.h> | - | ||||||||||||||||||||||||
77 | #endif | - | ||||||||||||||||||||||||
78 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||||||||
79 | # include <sys/types.h> | - | ||||||||||||||||||||||||
80 | # include <sys/stat.h> | - | ||||||||||||||||||||||||
81 | # include <unistd.h> | - | ||||||||||||||||||||||||
82 | # include "private/qcore_unix_p.h" | - | ||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||
#ifndef __has_include | ||||||||||||||||||||||||||
# define __has_include(x) 0#endif | ||||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
86 | #if !defined QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
87 | # ifdef __UCLIBC__ | - | ||||||||||||||||||||||||
88 | # if __UCLIBC_HAS_BACKTRACE__ | - | ||||||||||||||||||||||||
89 | # define QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
90 | # endif | - | ||||||||||||||||||||||||
91 | # elif (defined(__GLIBC__) && defined(__GLIBCXX__)) || (__has_includeQT_HAS_INCLUDE(<cxxabi.h>) && __has_includeQT_HAS_INCLUDE(<execinfo.h>)) | - | ||||||||||||||||||||||||
92 | # define QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
93 | # endif | - | ||||||||||||||||||||||||
94 | #endif | - | ||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | #if defined(QT_USE_SLOG2) | - | ||||||||||||||||||||||||
97 | extern char *__progname; | - | ||||||||||||||||||||||||
98 | #endif | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | #if defined(Q_OS_LINUX) && (defined(__GLIBC__) || __has_includeQT_HAS_INCLUDE(<sys/syscall.h>)) | - | ||||||||||||||||||||||||
101 | # include <sys/syscall.h> | - | ||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||
103 | # if defined(Q_OS_ANDROID) && !defined(SYS_gettid) | - | ||||||||||||||||||||||||
104 | # define SYS_gettid __NR_gettid | - | ||||||||||||||||||||||||
105 | # endif | - | ||||||||||||||||||||||||
106 | - | |||||||||||||||||||||||||
107 | static long qt_gettid() | - | ||||||||||||||||||||||||
108 | { | - | ||||||||||||||||||||||||
109 | // no error handling | - | ||||||||||||||||||||||||
110 | // this syscall has existed since Linux 2.4.11 and cannot fail | - | ||||||||||||||||||||||||
111 | return syscall(SYS_gettid); | - | ||||||||||||||||||||||||
112 | } | - | ||||||||||||||||||||||||
113 | #elif defined(Q_OS_DARWIN) | - | ||||||||||||||||||||||||
114 | # include <pthread.h> | - | ||||||||||||||||||||||||
115 | static int qt_gettid() | - | ||||||||||||||||||||||||
116 | { | - | ||||||||||||||||||||||||
117 | // no error handling: this call cannot fail | - | ||||||||||||||||||||||||
118 | __uint64_t tid; | - | ||||||||||||||||||||||||
119 | pthread_threadid_np(NULL, &tid); | - | ||||||||||||||||||||||||
120 | return tid; | - | ||||||||||||||||||||||||
121 | } | - | ||||||||||||||||||||||||
122 | #elif defined(Q_OS_FREEBSD_KERNEL) && defined(__FreeBSD_version) && __FreeBSD_version >= 900031 | - | ||||||||||||||||||||||||
123 | # include <pthread_np.h> | - | ||||||||||||||||||||||||
124 | static int qt_gettid() | - | ||||||||||||||||||||||||
125 | { | - | ||||||||||||||||||||||||
126 | return pthread_getthreadid_np(); | - | ||||||||||||||||||||||||
127 | } | - | ||||||||||||||||||||||||
128 | #else | - | ||||||||||||||||||||||||
129 | static QT_PREPEND_NAMESPACE(qint64) qt_gettid() | - | ||||||||||||||||||||||||
130 | { | - | ||||||||||||||||||||||||
131 | QT_USE_NAMESPACE | - | ||||||||||||||||||||||||
132 | return qintptr(QThread::currentThreadId()); | - | ||||||||||||||||||||||||
133 | } | - | ||||||||||||||||||||||||
134 | #endif | - | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
137 | # include <qregularexpression.h> | - | ||||||||||||||||||||||||
138 | # include <cxxabi.h> | - | ||||||||||||||||||||||||
139 | # include <execinfo.h> | - | ||||||||||||||||||||||||
140 | #endif | - | ||||||||||||||||||||||||
141 | #endif // !QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
142 | - | |||||||||||||||||||||||||
143 | #include <stdio.h> | - | ||||||||||||||||||||||||
144 | - | |||||||||||||||||||||||||
145 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
146 | - | |||||||||||||||||||||||||
147 | #if !defined(Q_CC_MSVC) | - | ||||||||||||||||||||||||
148 | Q_NORETURN | - | ||||||||||||||||||||||||
149 | #endif | - | ||||||||||||||||||||||||
150 | static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, const QString &message); | - | ||||||||||||||||||||||||
151 | static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message); | - | ||||||||||||||||||||||||
152 | - | |||||||||||||||||||||||||
153 | static bool isFatal(QtMsgType msgType) | - | ||||||||||||||||||||||||
154 | { | - | ||||||||||||||||||||||||
155 | if (msgType == QtFatalMsg) | - | ||||||||||||||||||||||||
156 | return true; | - | ||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||
158 | if (msgType == QtCriticalMsg) { | - | ||||||||||||||||||||||||
159 | static bool fatalCriticals = !qEnvironmentVariableIsEmpty("QT_FATAL_CRITICALS"); | - | ||||||||||||||||||||||||
160 | return fatalCriticals; | - | ||||||||||||||||||||||||
161 | } | - | ||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||
163 | if (msgType == QtWarningMsg || msgType == QtCriticalMsg) { | - | ||||||||||||||||||||||||
164 | static bool fatalWarnings = !qEnvironmentVariableIsEmpty("QT_FATAL_WARNINGS"); | - | ||||||||||||||||||||||||
165 | return fatalWarnings; | - | ||||||||||||||||||||||||
166 | } | - | ||||||||||||||||||||||||
167 | - | |||||||||||||||||||||||||
168 | return false; | - | ||||||||||||||||||||||||
169 | } | - | ||||||||||||||||||||||||
170 | - | |||||||||||||||||||||||||
171 | static bool willLogToConsole() | - | ||||||||||||||||||||||||
172 | { | - | ||||||||||||||||||||||||
173 | #if defined(Q_OS_WINCE) || defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
174 | // these systems have no stderr, so always log to the system log | - | ||||||||||||||||||||||||
175 | return false; | - | ||||||||||||||||||||||||
176 | #elif defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
177 | return true; | - | ||||||||||||||||||||||||
178 | #else | - | ||||||||||||||||||||||||
179 | // rules to determine if we'll log preferably to the console: | - | ||||||||||||||||||||||||
180 | // 1) if QT_LOGGING_TO_CONSOLE is set, it determines behavior: | - | ||||||||||||||||||||||||
181 | // - if it's set to 0, we will not log to console | - | ||||||||||||||||||||||||
182 | // - if it's set to 1, we will log to console | - | ||||||||||||||||||||||||
183 | // 2) otherwise, we will log to console if we have a console window (Windows) | - | ||||||||||||||||||||||||
184 | // or a controlling TTY (Unix). This is done even if stderr was redirected | - | ||||||||||||||||||||||||
185 | // to the blackhole device (NUL or /dev/null). | - | ||||||||||||||||||||||||
186 | - | |||||||||||||||||||||||||
187 | bool ok = true; | - | ||||||||||||||||||||||||
188 | uint envcontrol = qgetenv("QT_LOGGING_TO_CONSOLE").toUInt(&ok); | - | ||||||||||||||||||||||||
189 | if (ok) | - | ||||||||||||||||||||||||
190 | return envcontrol; | - | ||||||||||||||||||||||||
191 | - | |||||||||||||||||||||||||
192 | # ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
193 | return GetConsoleWindow(); | - | ||||||||||||||||||||||||
194 | # elif defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
195 | // if /dev/tty exists, we can only open it if we have a controlling TTY | - | ||||||||||||||||||||||||
196 | int devtty = qt_safe_open("/dev/tty", O_RDONLY); | - | ||||||||||||||||||||||||
197 | if (devtty == -1 && (errno == ENOENT || errno == EPERM)) { | - | ||||||||||||||||||||||||
198 | // no /dev/tty, fall back to isatty on stderr | - | ||||||||||||||||||||||||
199 | return isatty(STDERR_FILENO); | - | ||||||||||||||||||||||||
200 | } else if (devtty != -1) { | - | ||||||||||||||||||||||||
201 | // there is a /dev/tty and we could open it: we have a controlling TTY | - | ||||||||||||||||||||||||
202 | qt_safe_close(devtty); | - | ||||||||||||||||||||||||
203 | return true; | - | ||||||||||||||||||||||||
204 | } | - | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | // no controlling TTY | - | ||||||||||||||||||||||||
207 | return false; | - | ||||||||||||||||||||||||
208 | # else | - | ||||||||||||||||||||||||
209 | # error "Not Unix and not Windows?" | - | ||||||||||||||||||||||||
210 | # endif | - | ||||||||||||||||||||||||
211 | #endif | - | ||||||||||||||||||||||||
212 | } | - | ||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||
214 | Q_CORE_EXPORT bool qt_logging_to_console() | - | ||||||||||||||||||||||||
215 | { | - | ||||||||||||||||||||||||
216 | static const bool logToConsole = willLogToConsole(); | - | ||||||||||||||||||||||||
217 | return logToConsole; | - | ||||||||||||||||||||||||
218 | } | - | ||||||||||||||||||||||||
219 | - | |||||||||||||||||||||||||
220 | /*! | - | ||||||||||||||||||||||||
221 | \class QMessageLogContext | - | ||||||||||||||||||||||||
222 | \inmodule QtCore | - | ||||||||||||||||||||||||
223 | \brief The QMessageLogContext class provides additional information about a log message. | - | ||||||||||||||||||||||||
224 | \since 5.0 | - | ||||||||||||||||||||||||
225 | - | |||||||||||||||||||||||||
226 | The class provides information about the source code location a qDebug(), qInfo(), qWarning(), | - | ||||||||||||||||||||||||
227 | qCritical() or qFatal() message was generated. | - | ||||||||||||||||||||||||
228 | - | |||||||||||||||||||||||||
229 | \note By default, this information is recorded only in debug builds. You can overwrite | - | ||||||||||||||||||||||||
230 | this explicitly by defining \c QT_MESSAGELOGCONTEXT or \c{QT_NO_MESSAGELOGCONTEXT}. | - | ||||||||||||||||||||||||
231 | - | |||||||||||||||||||||||||
232 | \sa QMessageLogger, QtMessageHandler, qInstallMessageHandler() | - | ||||||||||||||||||||||||
233 | */ | - | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | /*! | - | ||||||||||||||||||||||||
236 | \class QMessageLogger | - | ||||||||||||||||||||||||
237 | \inmodule QtCore | - | ||||||||||||||||||||||||
238 | \brief The QMessageLogger class generates log messages. | - | ||||||||||||||||||||||||
239 | \since 5.0 | - | ||||||||||||||||||||||||
240 | - | |||||||||||||||||||||||||
241 | QMessageLogger is used to generate messages for the Qt logging framework. Usually one uses | - | ||||||||||||||||||||||||
242 | it through qDebug(), qInfo(), qWarning(), qCritical, or qFatal() functions, | - | ||||||||||||||||||||||||
243 | which are actually macros: For example qDebug() expands to | - | ||||||||||||||||||||||||
244 | QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug() | - | ||||||||||||||||||||||||
245 | for debug builds, and QMessageLogger(0, 0, 0).debug() for release builds. | - | ||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||
247 | One example of direct use is to forward errors that stem from a scripting language, e.g. QML: | - | ||||||||||||||||||||||||
248 | - | |||||||||||||||||||||||||
249 | \snippet code/qlogging/qlogging.cpp 1 | - | ||||||||||||||||||||||||
250 | - | |||||||||||||||||||||||||
251 | \sa QMessageLogContext, qDebug(), qInfo(), qWarning(), qCritical(), qFatal() | - | ||||||||||||||||||||||||
252 | */ | - | ||||||||||||||||||||||||
253 | - | |||||||||||||||||||||||||
254 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
255 | static inline void convert_to_wchar_t_elided(wchar_t *d, size_t space, const char *s) Q_DECL_NOEXCEPT | - | ||||||||||||||||||||||||
256 | { | - | ||||||||||||||||||||||||
257 | size_t len = qstrlen(s); | - | ||||||||||||||||||||||||
258 | if (len + 1 > space) { | - | ||||||||||||||||||||||||
259 | const size_t skip = len - space + 4; // 4 for "..." + '\0' | - | ||||||||||||||||||||||||
260 | s += skip; | - | ||||||||||||||||||||||||
261 | len -= skip; | - | ||||||||||||||||||||||||
262 | for (int i = 0; i < 3; ++i) | - | ||||||||||||||||||||||||
263 | *d++ = L'.'; | - | ||||||||||||||||||||||||
264 | } | - | ||||||||||||||||||||||||
265 | while (len--) | - | ||||||||||||||||||||||||
266 | *d++ = *s++; | - | ||||||||||||||||||||||||
267 | *d++ = 0; | - | ||||||||||||||||||||||||
268 | } | - | ||||||||||||||||||||||||
269 | #endif | - | ||||||||||||||||||||||||
270 | - | |||||||||||||||||||||||||
271 | /*! | - | ||||||||||||||||||||||||
272 | \internal | - | ||||||||||||||||||||||||
273 | */ | - | ||||||||||||||||||||||||
274 | Q_NEVER_INLINE | - | ||||||||||||||||||||||||
275 | static QString qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap) | - | ||||||||||||||||||||||||
276 | { | - | ||||||||||||||||||||||||
277 | QString buf = QString::vasprintf(msg, ap); | - | ||||||||||||||||||||||||
278 | qt_message_print(msgType, context, buf); | - | ||||||||||||||||||||||||
279 | return buf; | - | ||||||||||||||||||||||||
280 | } | - | ||||||||||||||||||||||||
281 | - | |||||||||||||||||||||||||
282 | #undef qDebug | - | ||||||||||||||||||||||||
283 | /*! | - | ||||||||||||||||||||||||
284 | Logs a debug message specified with format \a msg. Additional | - | ||||||||||||||||||||||||
285 | parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
286 | - | |||||||||||||||||||||||||
287 | \sa qDebug() | - | ||||||||||||||||||||||||
288 | */ | - | ||||||||||||||||||||||||
289 | void QMessageLogger::debug(const char *msg, ...) const | - | ||||||||||||||||||||||||
290 | { | - | ||||||||||||||||||||||||
291 | va_list ap; | - | ||||||||||||||||||||||||
292 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
293 | const QString message = qt_message(QtDebugMsg, context, msg, ap); | - | ||||||||||||||||||||||||
294 | va_end(ap); | - | ||||||||||||||||||||||||
295 | - | |||||||||||||||||||||||||
296 | if (isFatal(QtDebugMsg)) | - | ||||||||||||||||||||||||
297 | qt_message_fatal(QtDebugMsg, context, message); | - | ||||||||||||||||||||||||
298 | } | - | ||||||||||||||||||||||||
299 | - | |||||||||||||||||||||||||
300 | - | |||||||||||||||||||||||||
301 | #undef qInfo | - | ||||||||||||||||||||||||
302 | /*! | - | ||||||||||||||||||||||||
303 | Logs an informational message specified with format \a msg. Additional | - | ||||||||||||||||||||||||
304 | parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
305 | - | |||||||||||||||||||||||||
306 | \sa qInfo() | - | ||||||||||||||||||||||||
307 | \since 5.5 | - | ||||||||||||||||||||||||
308 | */ | - | ||||||||||||||||||||||||
309 | void QMessageLogger::info(const char *msg, ...) const | - | ||||||||||||||||||||||||
310 | { | - | ||||||||||||||||||||||||
311 | va_list ap; | - | ||||||||||||||||||||||||
312 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
313 | const QString message = qt_message(QtInfoMsg, context, msg, ap); | - | ||||||||||||||||||||||||
314 | va_end(ap); | - | ||||||||||||||||||||||||
315 | - | |||||||||||||||||||||||||
316 | if (isFatal(QtInfoMsg)) | - | ||||||||||||||||||||||||
317 | qt_message_fatal(QtInfoMsg, context, message); | - | ||||||||||||||||||||||||
318 | } | - | ||||||||||||||||||||||||
319 | - | |||||||||||||||||||||||||
320 | /*! | - | ||||||||||||||||||||||||
321 | \typedef QMessageLogger::CategoryFunction | - | ||||||||||||||||||||||||
322 | - | |||||||||||||||||||||||||
323 | This is a typedef for a pointer to a function with the following | - | ||||||||||||||||||||||||
324 | signature: | - | ||||||||||||||||||||||||
325 | - | |||||||||||||||||||||||||
326 | \snippet code/qlogging/qlogging.cpp 2 | - | ||||||||||||||||||||||||
327 | - | |||||||||||||||||||||||||
328 | A function which this signature is generated by Q_DECLARE_LOGGING_CATEGORY, | - | ||||||||||||||||||||||||
329 | Q_LOGGING_CATEGORY. | - | ||||||||||||||||||||||||
330 | - | |||||||||||||||||||||||||
331 | \since 5.3 | - | ||||||||||||||||||||||||
332 | */ | - | ||||||||||||||||||||||||
333 | - | |||||||||||||||||||||||||
334 | /*! | - | ||||||||||||||||||||||||
335 | Logs a debug message specified with format \a msg for the context \a cat. | - | ||||||||||||||||||||||||
336 | Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||
338 | \since 5.3 | - | ||||||||||||||||||||||||
339 | \sa qCDebug() | - | ||||||||||||||||||||||||
340 | */ | - | ||||||||||||||||||||||||
341 | void QMessageLogger::debug(const QLoggingCategory &cat, const char *msg, ...) const | - | ||||||||||||||||||||||||
342 | { | - | ||||||||||||||||||||||||
343 | if (!cat.isDebugEnabled()) | - | ||||||||||||||||||||||||
344 | return; | - | ||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
347 | ctxt.copy(context); | - | ||||||||||||||||||||||||
348 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
349 | - | |||||||||||||||||||||||||
350 | va_list ap; | - | ||||||||||||||||||||||||
351 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
352 | const QString message = qt_message(QtDebugMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
353 | va_end(ap); | - | ||||||||||||||||||||||||
354 | - | |||||||||||||||||||||||||
355 | if (isFatal(QtDebugMsg)) | - | ||||||||||||||||||||||||
356 | qt_message_fatal(QtDebugMsg, ctxt, message); | - | ||||||||||||||||||||||||
357 | } | - | ||||||||||||||||||||||||
358 | - | |||||||||||||||||||||||||
359 | /*! | - | ||||||||||||||||||||||||
360 | Logs a debug message specified with format \a msg for the context returned | - | ||||||||||||||||||||||||
361 | by \a catFunc. Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
362 | - | |||||||||||||||||||||||||
363 | \since 5.3 | - | ||||||||||||||||||||||||
364 | \sa qCDebug() | - | ||||||||||||||||||||||||
365 | */ | - | ||||||||||||||||||||||||
366 | void QMessageLogger::debug(QMessageLogger::CategoryFunction catFunc, | - | ||||||||||||||||||||||||
367 | const char *msg, ...) const | - | ||||||||||||||||||||||||
368 | { | - | ||||||||||||||||||||||||
369 | const QLoggingCategory &cat = (*catFunc)(); | - | ||||||||||||||||||||||||
370 | if (!cat.isDebugEnabled()) | - | ||||||||||||||||||||||||
371 | return; | - | ||||||||||||||||||||||||
372 | - | |||||||||||||||||||||||||
373 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
374 | ctxt.copy(context); | - | ||||||||||||||||||||||||
375 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
376 | - | |||||||||||||||||||||||||
377 | va_list ap; | - | ||||||||||||||||||||||||
378 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
379 | const QString message = qt_message(QtDebugMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
380 | va_end(ap); | - | ||||||||||||||||||||||||
381 | - | |||||||||||||||||||||||||
382 | if (isFatal(QtDebugMsg)) | - | ||||||||||||||||||||||||
383 | qt_message_fatal(QtDebugMsg, ctxt, message); | - | ||||||||||||||||||||||||
384 | } | - | ||||||||||||||||||||||||
385 | - | |||||||||||||||||||||||||
386 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||
388 | /*! | - | ||||||||||||||||||||||||
389 | Logs a debug message using a QDebug stream | - | ||||||||||||||||||||||||
390 | - | |||||||||||||||||||||||||
391 | \sa qDebug(), QDebug | - | ||||||||||||||||||||||||
392 | */ | - | ||||||||||||||||||||||||
393 | QDebug QMessageLogger::debug() const | - | ||||||||||||||||||||||||
394 | { | - | ||||||||||||||||||||||||
395 | QDebug dbg = QDebug(QtDebugMsg); | - | ||||||||||||||||||||||||
396 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
397 | ctxt.copy(context); | - | ||||||||||||||||||||||||
398 | return dbg; | - | ||||||||||||||||||||||||
399 | } | - | ||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||
401 | /*! | - | ||||||||||||||||||||||||
402 | Logs a debug message into category \a cat using a QDebug stream. | - | ||||||||||||||||||||||||
403 | - | |||||||||||||||||||||||||
404 | \since 5.3 | - | ||||||||||||||||||||||||
405 | \sa qCDebug(), QDebug | - | ||||||||||||||||||||||||
406 | */ | - | ||||||||||||||||||||||||
407 | QDebug QMessageLogger::debug(const QLoggingCategory &cat) const | - | ||||||||||||||||||||||||
408 | { | - | ||||||||||||||||||||||||
409 | QDebug dbg = QDebug(QtDebugMsg); | - | ||||||||||||||||||||||||
410 | if (!cat.isDebugEnabled()) | - | ||||||||||||||||||||||||
411 | dbg.stream->message_output = false; | - | ||||||||||||||||||||||||
412 | - | |||||||||||||||||||||||||
413 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
414 | ctxt.copy(context); | - | ||||||||||||||||||||||||
415 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
416 | - | |||||||||||||||||||||||||
417 | return dbg; | - | ||||||||||||||||||||||||
418 | } | - | ||||||||||||||||||||||||
419 | - | |||||||||||||||||||||||||
420 | /*! | - | ||||||||||||||||||||||||
421 | Logs a debug message into category returned by \a catFunc using a QDebug stream. | - | ||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||
423 | \since 5.3 | - | ||||||||||||||||||||||||
424 | \sa qCDebug(), QDebug | - | ||||||||||||||||||||||||
425 | */ | - | ||||||||||||||||||||||||
426 | QDebug QMessageLogger::debug(QMessageLogger::CategoryFunction catFunc) const | - | ||||||||||||||||||||||||
427 | { | - | ||||||||||||||||||||||||
428 | return debug((*catFunc)()); | - | ||||||||||||||||||||||||
429 | } | - | ||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | /*! | - | ||||||||||||||||||||||||
432 | \internal | - | ||||||||||||||||||||||||
433 | - | |||||||||||||||||||||||||
434 | Returns a QNoDebug object, which is used to ignore debugging output. | - | ||||||||||||||||||||||||
435 | - | |||||||||||||||||||||||||
436 | \sa QNoDebug, qDebug() | - | ||||||||||||||||||||||||
437 | */ | - | ||||||||||||||||||||||||
438 | QNoDebug QMessageLogger::noDebug() const Q_DECL_NOTHROW | - | ||||||||||||||||||||||||
439 | { | - | ||||||||||||||||||||||||
440 | return QNoDebug(); never executed: return QNoDebug(); | 0 | ||||||||||||||||||||||||
441 | } | - | ||||||||||||||||||||||||
442 | - | |||||||||||||||||||||||||
443 | #endif | - | ||||||||||||||||||||||||
444 | - | |||||||||||||||||||||||||
445 | /*! | - | ||||||||||||||||||||||||
446 | Logs an informational message specified with format \a msg for the context \a cat. | - | ||||||||||||||||||||||||
447 | Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
448 | - | |||||||||||||||||||||||||
449 | \since 5.5 | - | ||||||||||||||||||||||||
450 | \sa qCInfo() | - | ||||||||||||||||||||||||
451 | */ | - | ||||||||||||||||||||||||
452 | void QMessageLogger::info(const QLoggingCategory &cat, const char *msg, ...) const | - | ||||||||||||||||||||||||
453 | { | - | ||||||||||||||||||||||||
454 | if (!cat.isInfoEnabled()) | - | ||||||||||||||||||||||||
455 | return; | - | ||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||
457 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
458 | ctxt.copy(context); | - | ||||||||||||||||||||||||
459 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||
461 | va_list ap; | - | ||||||||||||||||||||||||
462 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
463 | const QString message = qt_message(QtInfoMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
464 | va_end(ap); | - | ||||||||||||||||||||||||
465 | - | |||||||||||||||||||||||||
466 | if (isFatal(QtInfoMsg)) | - | ||||||||||||||||||||||||
467 | qt_message_fatal(QtInfoMsg, ctxt, message); | - | ||||||||||||||||||||||||
468 | } | - | ||||||||||||||||||||||||
469 | - | |||||||||||||||||||||||||
470 | /*! | - | ||||||||||||||||||||||||
471 | Logs an informational message specified with format \a msg for the context returned | - | ||||||||||||||||||||||||
472 | by \a catFunc. Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
473 | - | |||||||||||||||||||||||||
474 | \since 5.5 | - | ||||||||||||||||||||||||
475 | \sa qCInfo() | - | ||||||||||||||||||||||||
476 | */ | - | ||||||||||||||||||||||||
477 | void QMessageLogger::info(QMessageLogger::CategoryFunction catFunc, | - | ||||||||||||||||||||||||
478 | const char *msg, ...) const | - | ||||||||||||||||||||||||
479 | { | - | ||||||||||||||||||||||||
480 | const QLoggingCategory &cat = (*catFunc)(); | - | ||||||||||||||||||||||||
481 | if (!cat.isInfoEnabled()) | - | ||||||||||||||||||||||||
482 | return; | - | ||||||||||||||||||||||||
483 | - | |||||||||||||||||||||||||
484 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
485 | ctxt.copy(context); | - | ||||||||||||||||||||||||
486 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
487 | - | |||||||||||||||||||||||||
488 | va_list ap; | - | ||||||||||||||||||||||||
489 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
490 | const QString message = qt_message(QtInfoMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
491 | va_end(ap); | - | ||||||||||||||||||||||||
492 | - | |||||||||||||||||||||||||
493 | if (isFatal(QtInfoMsg)) | - | ||||||||||||||||||||||||
494 | qt_message_fatal(QtInfoMsg, ctxt, message); | - | ||||||||||||||||||||||||
495 | } | - | ||||||||||||||||||||||||
496 | - | |||||||||||||||||||||||||
497 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
498 | - | |||||||||||||||||||||||||
499 | /*! | - | ||||||||||||||||||||||||
500 | Logs an informational message using a QDebug stream. | - | ||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||
502 | \since 5.5 | - | ||||||||||||||||||||||||
503 | \sa qInfo(), QDebug | - | ||||||||||||||||||||||||
504 | */ | - | ||||||||||||||||||||||||
505 | QDebug QMessageLogger::info() const | - | ||||||||||||||||||||||||
506 | { | - | ||||||||||||||||||||||||
507 | QDebug dbg = QDebug(QtInfoMsg); | - | ||||||||||||||||||||||||
508 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
509 | ctxt.copy(context); | - | ||||||||||||||||||||||||
510 | return dbg; | - | ||||||||||||||||||||||||
511 | } | - | ||||||||||||||||||||||||
512 | - | |||||||||||||||||||||||||
513 | /*! | - | ||||||||||||||||||||||||
514 | Logs an informational message into the category \a cat using a QDebug stream. | - | ||||||||||||||||||||||||
515 | - | |||||||||||||||||||||||||
516 | \since 5.5 | - | ||||||||||||||||||||||||
517 | \sa qCInfo(), QDebug | - | ||||||||||||||||||||||||
518 | */ | - | ||||||||||||||||||||||||
519 | QDebug QMessageLogger::info(const QLoggingCategory &cat) const | - | ||||||||||||||||||||||||
520 | { | - | ||||||||||||||||||||||||
521 | QDebug dbg = QDebug(QtInfoMsg); | - | ||||||||||||||||||||||||
522 | if (!cat.isInfoEnabled()) | - | ||||||||||||||||||||||||
523 | dbg.stream->message_output = false; | - | ||||||||||||||||||||||||
524 | - | |||||||||||||||||||||||||
525 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
526 | ctxt.copy(context); | - | ||||||||||||||||||||||||
527 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
528 | - | |||||||||||||||||||||||||
529 | return dbg; | - | ||||||||||||||||||||||||
530 | } | - | ||||||||||||||||||||||||
531 | - | |||||||||||||||||||||||||
532 | /*! | - | ||||||||||||||||||||||||
533 | Logs an informational message into category returned by \a catFunc using a QDebug stream. | - | ||||||||||||||||||||||||
534 | - | |||||||||||||||||||||||||
535 | \since 5.5 | - | ||||||||||||||||||||||||
536 | \sa qCInfo(), QDebug | - | ||||||||||||||||||||||||
537 | */ | - | ||||||||||||||||||||||||
538 | QDebug QMessageLogger::info(QMessageLogger::CategoryFunction catFunc) const | - | ||||||||||||||||||||||||
539 | { | - | ||||||||||||||||||||||||
540 | return info((*catFunc)()); | - | ||||||||||||||||||||||||
541 | } | - | ||||||||||||||||||||||||
542 | - | |||||||||||||||||||||||||
543 | #endif | - | ||||||||||||||||||||||||
544 | - | |||||||||||||||||||||||||
545 | #undef qWarning | - | ||||||||||||||||||||||||
546 | /*! | - | ||||||||||||||||||||||||
547 | Logs a warning message specified with format \a msg. Additional | - | ||||||||||||||||||||||||
548 | parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
549 | - | |||||||||||||||||||||||||
550 | \sa qWarning() | - | ||||||||||||||||||||||||
551 | */ | - | ||||||||||||||||||||||||
552 | void QMessageLogger::warning(const char *msg, ...) const | - | ||||||||||||||||||||||||
553 | { | - | ||||||||||||||||||||||||
554 | va_list ap; | - | ||||||||||||||||||||||||
555 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
556 | const QString message = qt_message(QtWarningMsg, context, msg, ap); | - | ||||||||||||||||||||||||
557 | va_end(ap); | - | ||||||||||||||||||||||||
558 | - | |||||||||||||||||||||||||
559 | if (isFatal(QtWarningMsg)) | - | ||||||||||||||||||||||||
560 | qt_message_fatal(QtWarningMsg, context, message); | - | ||||||||||||||||||||||||
561 | } | - | ||||||||||||||||||||||||
562 | - | |||||||||||||||||||||||||
563 | /*! | - | ||||||||||||||||||||||||
564 | Logs a warning message specified with format \a msg for the context \a cat. | - | ||||||||||||||||||||||||
565 | Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
566 | - | |||||||||||||||||||||||||
567 | \since 5.3 | - | ||||||||||||||||||||||||
568 | \sa qCWarning() | - | ||||||||||||||||||||||||
569 | */ | - | ||||||||||||||||||||||||
570 | void QMessageLogger::warning(const QLoggingCategory &cat, const char *msg, ...) const | - | ||||||||||||||||||||||||
571 | { | - | ||||||||||||||||||||||||
572 | if (!cat.isWarningEnabled()) | - | ||||||||||||||||||||||||
573 | return; | - | ||||||||||||||||||||||||
574 | - | |||||||||||||||||||||||||
575 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
576 | ctxt.copy(context); | - | ||||||||||||||||||||||||
577 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
578 | - | |||||||||||||||||||||||||
579 | va_list ap; | - | ||||||||||||||||||||||||
580 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
581 | const QString message = qt_message(QtWarningMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
582 | va_end(ap); | - | ||||||||||||||||||||||||
583 | - | |||||||||||||||||||||||||
584 | if (isFatal(QtWarningMsg)) | - | ||||||||||||||||||||||||
585 | qt_message_fatal(QtWarningMsg, ctxt, message); | - | ||||||||||||||||||||||||
586 | } | - | ||||||||||||||||||||||||
587 | - | |||||||||||||||||||||||||
588 | /*! | - | ||||||||||||||||||||||||
589 | Logs a warning message specified with format \a msg for the context returned | - | ||||||||||||||||||||||||
590 | by \a catFunc. Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
591 | - | |||||||||||||||||||||||||
592 | \since 5.3 | - | ||||||||||||||||||||||||
593 | \sa qCWarning() | - | ||||||||||||||||||||||||
594 | */ | - | ||||||||||||||||||||||||
595 | void QMessageLogger::warning(QMessageLogger::CategoryFunction catFunc, | - | ||||||||||||||||||||||||
596 | const char *msg, ...) const | - | ||||||||||||||||||||||||
597 | { | - | ||||||||||||||||||||||||
598 | const QLoggingCategory &cat = (*catFunc)(); | - | ||||||||||||||||||||||||
599 | if (!cat.isWarningEnabled()) | - | ||||||||||||||||||||||||
600 | return; | - | ||||||||||||||||||||||||
601 | - | |||||||||||||||||||||||||
602 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
603 | ctxt.copy(context); | - | ||||||||||||||||||||||||
604 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
605 | - | |||||||||||||||||||||||||
606 | va_list ap; | - | ||||||||||||||||||||||||
607 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
608 | const QString message = qt_message(QtWarningMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
609 | va_end(ap); | - | ||||||||||||||||||||||||
610 | - | |||||||||||||||||||||||||
611 | if (isFatal(QtWarningMsg)) | - | ||||||||||||||||||||||||
612 | qt_message_fatal(QtWarningMsg, ctxt, message); | - | ||||||||||||||||||||||||
613 | } | - | ||||||||||||||||||||||||
614 | - | |||||||||||||||||||||||||
615 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
616 | /*! | - | ||||||||||||||||||||||||
617 | Logs a warning message using a QDebug stream | - | ||||||||||||||||||||||||
618 | - | |||||||||||||||||||||||||
619 | \sa qWarning(), QDebug | - | ||||||||||||||||||||||||
620 | */ | - | ||||||||||||||||||||||||
621 | QDebug QMessageLogger::warning() const | - | ||||||||||||||||||||||||
622 | { | - | ||||||||||||||||||||||||
623 | QDebug dbg = QDebug(QtWarningMsg); | - | ||||||||||||||||||||||||
624 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
625 | ctxt.copy(context); | - | ||||||||||||||||||||||||
626 | return dbg; | - | ||||||||||||||||||||||||
627 | } | - | ||||||||||||||||||||||||
628 | - | |||||||||||||||||||||||||
629 | /*! | - | ||||||||||||||||||||||||
630 | Logs a warning message into category \a cat using a QDebug stream. | - | ||||||||||||||||||||||||
631 | - | |||||||||||||||||||||||||
632 | \sa qCWarning(), QDebug | - | ||||||||||||||||||||||||
633 | */ | - | ||||||||||||||||||||||||
634 | QDebug QMessageLogger::warning(const QLoggingCategory &cat) const | - | ||||||||||||||||||||||||
635 | { | - | ||||||||||||||||||||||||
636 | QDebug dbg = QDebug(QtWarningMsg); | - | ||||||||||||||||||||||||
637 | if (!cat.isWarningEnabled()) | - | ||||||||||||||||||||||||
638 | dbg.stream->message_output = false; | - | ||||||||||||||||||||||||
639 | - | |||||||||||||||||||||||||
640 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
641 | ctxt.copy(context); | - | ||||||||||||||||||||||||
642 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
643 | - | |||||||||||||||||||||||||
644 | return dbg; | - | ||||||||||||||||||||||||
645 | } | - | ||||||||||||||||||||||||
646 | - | |||||||||||||||||||||||||
647 | /*! | - | ||||||||||||||||||||||||
648 | Logs a warning message into category returned by \a catFunc using a QDebug stream. | - | ||||||||||||||||||||||||
649 | - | |||||||||||||||||||||||||
650 | \since 5.3 | - | ||||||||||||||||||||||||
651 | \sa qCWarning(), QDebug | - | ||||||||||||||||||||||||
652 | */ | - | ||||||||||||||||||||||||
653 | QDebug QMessageLogger::warning(QMessageLogger::CategoryFunction catFunc) const | - | ||||||||||||||||||||||||
654 | { | - | ||||||||||||||||||||||||
655 | return warning((*catFunc)()); | - | ||||||||||||||||||||||||
656 | } | - | ||||||||||||||||||||||||
657 | - | |||||||||||||||||||||||||
658 | #endif | - | ||||||||||||||||||||||||
659 | - | |||||||||||||||||||||||||
660 | #undef qCritical | - | ||||||||||||||||||||||||
661 | - | |||||||||||||||||||||||||
662 | /*! | - | ||||||||||||||||||||||||
663 | Logs a critical message specified with format \a msg. Additional | - | ||||||||||||||||||||||||
664 | parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
665 | - | |||||||||||||||||||||||||
666 | \sa qCritical() | - | ||||||||||||||||||||||||
667 | */ | - | ||||||||||||||||||||||||
668 | void QMessageLogger::critical(const char *msg, ...) const | - | ||||||||||||||||||||||||
669 | { | - | ||||||||||||||||||||||||
670 | va_list ap; | - | ||||||||||||||||||||||||
671 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
672 | const QString message = qt_message(QtCriticalMsg, context, msg, ap); | - | ||||||||||||||||||||||||
673 | va_end(ap); | - | ||||||||||||||||||||||||
674 | - | |||||||||||||||||||||||||
675 | if (isFatal(QtCriticalMsg)) | - | ||||||||||||||||||||||||
676 | qt_message_fatal(QtCriticalMsg, context, message); | - | ||||||||||||||||||||||||
677 | } | - | ||||||||||||||||||||||||
678 | - | |||||||||||||||||||||||||
679 | /*! | - | ||||||||||||||||||||||||
680 | Logs a critical message specified with format \a msg for the context \a cat. | - | ||||||||||||||||||||||||
681 | Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
682 | - | |||||||||||||||||||||||||
683 | \since 5.3 | - | ||||||||||||||||||||||||
684 | \sa qCCritical() | - | ||||||||||||||||||||||||
685 | */ | - | ||||||||||||||||||||||||
686 | void QMessageLogger::critical(const QLoggingCategory &cat, const char *msg, ...) const | - | ||||||||||||||||||||||||
687 | { | - | ||||||||||||||||||||||||
688 | if (!cat.isCriticalEnabled()) | - | ||||||||||||||||||||||||
689 | return; | - | ||||||||||||||||||||||||
690 | - | |||||||||||||||||||||||||
691 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
692 | ctxt.copy(context); | - | ||||||||||||||||||||||||
693 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
694 | - | |||||||||||||||||||||||||
695 | va_list ap; | - | ||||||||||||||||||||||||
696 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
697 | const QString message = qt_message(QtCriticalMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
698 | va_end(ap); | - | ||||||||||||||||||||||||
699 | - | |||||||||||||||||||||||||
700 | if (isFatal(QtCriticalMsg)) | - | ||||||||||||||||||||||||
701 | qt_message_fatal(QtCriticalMsg, ctxt, message); | - | ||||||||||||||||||||||||
702 | } | - | ||||||||||||||||||||||||
703 | - | |||||||||||||||||||||||||
704 | /*! | - | ||||||||||||||||||||||||
705 | Logs a critical message specified with format \a msg for the context returned | - | ||||||||||||||||||||||||
706 | by \a catFunc. Additional parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
707 | - | |||||||||||||||||||||||||
708 | \since 5.3 | - | ||||||||||||||||||||||||
709 | \sa qCCritical() | - | ||||||||||||||||||||||||
710 | */ | - | ||||||||||||||||||||||||
711 | void QMessageLogger::critical(QMessageLogger::CategoryFunction catFunc, | - | ||||||||||||||||||||||||
712 | const char *msg, ...) const | - | ||||||||||||||||||||||||
713 | { | - | ||||||||||||||||||||||||
714 | const QLoggingCategory &cat = (*catFunc)(); | - | ||||||||||||||||||||||||
715 | if (!cat.isCriticalEnabled()) | - | ||||||||||||||||||||||||
716 | return; | - | ||||||||||||||||||||||||
717 | - | |||||||||||||||||||||||||
718 | QMessageLogContext ctxt; | - | ||||||||||||||||||||||||
719 | ctxt.copy(context); | - | ||||||||||||||||||||||||
720 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
721 | - | |||||||||||||||||||||||||
722 | va_list ap; | - | ||||||||||||||||||||||||
723 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
724 | const QString message = qt_message(QtCriticalMsg, ctxt, msg, ap); | - | ||||||||||||||||||||||||
725 | va_end(ap); | - | ||||||||||||||||||||||||
726 | - | |||||||||||||||||||||||||
727 | if (isFatal(QtCriticalMsg)) | - | ||||||||||||||||||||||||
728 | qt_message_fatal(QtCriticalMsg, ctxt, message); | - | ||||||||||||||||||||||||
729 | } | - | ||||||||||||||||||||||||
730 | - | |||||||||||||||||||||||||
731 | #ifndef QT_NO_DEBUG_STREAM | - | ||||||||||||||||||||||||
732 | /*! | - | ||||||||||||||||||||||||
733 | Logs a critical message using a QDebug stream | - | ||||||||||||||||||||||||
734 | - | |||||||||||||||||||||||||
735 | \sa qCritical(), QDebug | - | ||||||||||||||||||||||||
736 | */ | - | ||||||||||||||||||||||||
737 | QDebug QMessageLogger::critical() const | - | ||||||||||||||||||||||||
738 | { | - | ||||||||||||||||||||||||
739 | QDebug dbg = QDebug(QtCriticalMsg); | - | ||||||||||||||||||||||||
740 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
741 | ctxt.copy(context); | - | ||||||||||||||||||||||||
742 | return dbg; | - | ||||||||||||||||||||||||
743 | } | - | ||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||
745 | /*! | - | ||||||||||||||||||||||||
746 | Logs a critical message into category \a cat using a QDebug stream. | - | ||||||||||||||||||||||||
747 | - | |||||||||||||||||||||||||
748 | \since 5.3 | - | ||||||||||||||||||||||||
749 | \sa qCCritical(), QDebug | - | ||||||||||||||||||||||||
750 | */ | - | ||||||||||||||||||||||||
751 | QDebug QMessageLogger::critical(const QLoggingCategory &cat) const | - | ||||||||||||||||||||||||
752 | { | - | ||||||||||||||||||||||||
753 | QDebug dbg = QDebug(QtCriticalMsg); | - | ||||||||||||||||||||||||
754 | if (!cat.isCriticalEnabled()) | - | ||||||||||||||||||||||||
755 | dbg.stream->message_output = false; | - | ||||||||||||||||||||||||
756 | - | |||||||||||||||||||||||||
757 | QMessageLogContext &ctxt = dbg.stream->context; | - | ||||||||||||||||||||||||
758 | ctxt.copy(context); | - | ||||||||||||||||||||||||
759 | ctxt.category = cat.categoryName(); | - | ||||||||||||||||||||||||
760 | - | |||||||||||||||||||||||||
761 | return dbg; | - | ||||||||||||||||||||||||
762 | } | - | ||||||||||||||||||||||||
763 | - | |||||||||||||||||||||||||
764 | /*! | - | ||||||||||||||||||||||||
765 | Logs a critical message into category returned by \a catFunc using a QDebug stream. | - | ||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | \since 5.3 | - | ||||||||||||||||||||||||
768 | \sa qCCritical(), QDebug | - | ||||||||||||||||||||||||
769 | */ | - | ||||||||||||||||||||||||
770 | QDebug QMessageLogger::critical(QMessageLogger::CategoryFunction catFunc) const | - | ||||||||||||||||||||||||
771 | { | - | ||||||||||||||||||||||||
772 | return critical((*catFunc)()); | - | ||||||||||||||||||||||||
773 | } | - | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
775 | #endif | - | ||||||||||||||||||||||||
776 | - | |||||||||||||||||||||||||
777 | #undef qFatal | - | ||||||||||||||||||||||||
778 | /*! | - | ||||||||||||||||||||||||
779 | Logs a fatal message specified with format \a msg. Additional | - | ||||||||||||||||||||||||
780 | parameters, specified by \a msg, may be used. | - | ||||||||||||||||||||||||
781 | - | |||||||||||||||||||||||||
782 | \sa qFatal() | - | ||||||||||||||||||||||||
783 | */ | - | ||||||||||||||||||||||||
784 | void QMessageLogger::fatal(const char *msg, ...) const Q_DECL_NOTHROW | - | ||||||||||||||||||||||||
785 | { | - | ||||||||||||||||||||||||
786 | QString message; | - | ||||||||||||||||||||||||
787 | - | |||||||||||||||||||||||||
788 | va_list ap; | - | ||||||||||||||||||||||||
789 | va_start(ap, msg); // use variable arg list | - | ||||||||||||||||||||||||
790 | QT_TERMINATE_ON_EXCEPTION(message = qt_message(QtFatalMsg, context, msg, ap)); | - | ||||||||||||||||||||||||
791 | va_end(ap); | - | ||||||||||||||||||||||||
792 | - | |||||||||||||||||||||||||
793 | qt_message_fatal(QtFatalMsg, context, message); | - | ||||||||||||||||||||||||
794 | } never executed: end of block | 0 | ||||||||||||||||||||||||
795 | - | |||||||||||||||||||||||||
796 | /*! | - | ||||||||||||||||||||||||
797 | \internal | - | ||||||||||||||||||||||||
798 | */ | - | ||||||||||||||||||||||||
799 | Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info) | - | ||||||||||||||||||||||||
800 | { | - | ||||||||||||||||||||||||
801 | // Strip the function info down to the base function name | - | ||||||||||||||||||||||||
802 | // note that this throws away the template definitions, | - | ||||||||||||||||||||||||
803 | // the parameter types (overloads) and any const/volatile qualifiers. | - | ||||||||||||||||||||||||
804 | - | |||||||||||||||||||||||||
805 | if (info.isEmpty()) | - | ||||||||||||||||||||||||
806 | return info; | - | ||||||||||||||||||||||||
807 | - | |||||||||||||||||||||||||
808 | int pos; | - | ||||||||||||||||||||||||
809 | - | |||||||||||||||||||||||||
810 | // Skip trailing [with XXX] for templates (gcc), but make | - | ||||||||||||||||||||||||
811 | // sure to not affect Objective-C message names. | - | ||||||||||||||||||||||||
812 | pos = info.size() - 1; | - | ||||||||||||||||||||||||
813 | if (info.endsWith(']') && !(info.startsWith('+') || info.startsWith('-'))) { | - | ||||||||||||||||||||||||
814 | while (--pos) { | - | ||||||||||||||||||||||||
815 | if (info.at(pos) == '[') | - | ||||||||||||||||||||||||
816 | info.truncate(pos); | - | ||||||||||||||||||||||||
817 | } | - | ||||||||||||||||||||||||
818 | } | - | ||||||||||||||||||||||||
819 | - | |||||||||||||||||||||||||
820 | // operator names with '(', ')', '<', '>' in it | - | ||||||||||||||||||||||||
821 | static const char operator_call[] = "operator()"; | - | ||||||||||||||||||||||||
822 | static const char operator_lessThan[] = "operator<"; | - | ||||||||||||||||||||||||
823 | static const char operator_greaterThan[] = "operator>"; | - | ||||||||||||||||||||||||
824 | static const char operator_lessThanEqual[] = "operator<="; | - | ||||||||||||||||||||||||
825 | static const char operator_greaterThanEqual[] = "operator>="; | - | ||||||||||||||||||||||||
826 | - | |||||||||||||||||||||||||
827 | // canonize operator names | - | ||||||||||||||||||||||||
828 | info.replace("operator ", "operator"); | - | ||||||||||||||||||||||||
829 | - | |||||||||||||||||||||||||
830 | // remove argument list | - | ||||||||||||||||||||||||
831 | forever { | - | ||||||||||||||||||||||||
832 | int parencount = 0; | - | ||||||||||||||||||||||||
833 | pos = info.lastIndexOf(')'); | - | ||||||||||||||||||||||||
834 | if (pos == -1) { | - | ||||||||||||||||||||||||
835 | // Don't know how to parse this function name | - | ||||||||||||||||||||||||
836 | return info; | - | ||||||||||||||||||||||||
837 | } | - | ||||||||||||||||||||||||
838 | - | |||||||||||||||||||||||||
839 | // find the beginning of the argument list | - | ||||||||||||||||||||||||
840 | --pos; | - | ||||||||||||||||||||||||
841 | ++parencount; | - | ||||||||||||||||||||||||
842 | while (pos && parencount) { | - | ||||||||||||||||||||||||
843 | if (info.at(pos) == ')') | - | ||||||||||||||||||||||||
844 | ++parencount; | - | ||||||||||||||||||||||||
845 | else if (info.at(pos) == '(') | - | ||||||||||||||||||||||||
846 | --parencount; | - | ||||||||||||||||||||||||
847 | --pos; | - | ||||||||||||||||||||||||
848 | } | - | ||||||||||||||||||||||||
849 | if (parencount != 0) | - | ||||||||||||||||||||||||
850 | return info; | - | ||||||||||||||||||||||||
851 | - | |||||||||||||||||||||||||
852 | info.truncate(++pos); | - | ||||||||||||||||||||||||
853 | - | |||||||||||||||||||||||||
854 | if (info.at(pos - 1) == ')') { | - | ||||||||||||||||||||||||
855 | if (info.indexOf(operator_call) == pos - (int)strlen(operator_call)) | - | ||||||||||||||||||||||||
856 | break; | - | ||||||||||||||||||||||||
857 | - | |||||||||||||||||||||||||
858 | // this function returns a pointer to a function | - | ||||||||||||||||||||||||
859 | // and we matched the arguments of the return type's parameter list | - | ||||||||||||||||||||||||
860 | // try again | - | ||||||||||||||||||||||||
861 | info.remove(0, info.indexOf('(')); | - | ||||||||||||||||||||||||
862 | info.chop(1); | - | ||||||||||||||||||||||||
863 | continue; | - | ||||||||||||||||||||||||
864 | } else { | - | ||||||||||||||||||||||||
865 | break; | - | ||||||||||||||||||||||||
866 | } | - | ||||||||||||||||||||||||
867 | } | - | ||||||||||||||||||||||||
868 | - | |||||||||||||||||||||||||
869 | // find the beginning of the function name | - | ||||||||||||||||||||||||
870 | int parencount = 0; | - | ||||||||||||||||||||||||
871 | int templatecount = 0; | - | ||||||||||||||||||||||||
872 | --pos; | - | ||||||||||||||||||||||||
873 | - | |||||||||||||||||||||||||
874 | // make sure special characters in operator names are kept | - | ||||||||||||||||||||||||
875 | if (pos > -1) { | - | ||||||||||||||||||||||||
876 | switch (info.at(pos)) { | - | ||||||||||||||||||||||||
877 | case ')': | - | ||||||||||||||||||||||||
878 | if (info.indexOf(operator_call) == pos - (int)strlen(operator_call) + 1) | - | ||||||||||||||||||||||||
879 | pos -= 2; | - | ||||||||||||||||||||||||
880 | break; | - | ||||||||||||||||||||||||
881 | case '<': | - | ||||||||||||||||||||||||
882 | if (info.indexOf(operator_lessThan) == pos - (int)strlen(operator_lessThan) + 1) | - | ||||||||||||||||||||||||
883 | --pos; | - | ||||||||||||||||||||||||
884 | break; | - | ||||||||||||||||||||||||
885 | case '>': | - | ||||||||||||||||||||||||
886 | if (info.indexOf(operator_greaterThan) == pos - (int)strlen(operator_greaterThan) + 1) | - | ||||||||||||||||||||||||
887 | --pos; | - | ||||||||||||||||||||||||
888 | break; | - | ||||||||||||||||||||||||
889 | case '=': { | - | ||||||||||||||||||||||||
890 | int operatorLength = (int)strlen(operator_lessThanEqual); | - | ||||||||||||||||||||||||
891 | if (info.indexOf(operator_lessThanEqual) == pos - operatorLength + 1) | - | ||||||||||||||||||||||||
892 | pos -= 2; | - | ||||||||||||||||||||||||
893 | else if (info.indexOf(operator_greaterThanEqual) == pos - operatorLength + 1) | - | ||||||||||||||||||||||||
894 | pos -= 2; | - | ||||||||||||||||||||||||
895 | break; | - | ||||||||||||||||||||||||
896 | } | - | ||||||||||||||||||||||||
897 | default: | - | ||||||||||||||||||||||||
898 | break; | - | ||||||||||||||||||||||||
899 | } | - | ||||||||||||||||||||||||
900 | } | - | ||||||||||||||||||||||||
901 | - | |||||||||||||||||||||||||
902 | while (pos > -1) { | - | ||||||||||||||||||||||||
903 | if (parencount < 0 || templatecount < 0) | - | ||||||||||||||||||||||||
904 | return info; | - | ||||||||||||||||||||||||
905 | - | |||||||||||||||||||||||||
906 | char c = info.at(pos); | - | ||||||||||||||||||||||||
907 | if (c == ')') | - | ||||||||||||||||||||||||
908 | ++parencount; | - | ||||||||||||||||||||||||
909 | else if (c == '(') | - | ||||||||||||||||||||||||
910 | --parencount; | - | ||||||||||||||||||||||||
911 | else if (c == '>') | - | ||||||||||||||||||||||||
912 | ++templatecount; | - | ||||||||||||||||||||||||
913 | else if (c == '<') | - | ||||||||||||||||||||||||
914 | --templatecount; | - | ||||||||||||||||||||||||
915 | else if (c == ' ' && templatecount == 0 && parencount == 0) | - | ||||||||||||||||||||||||
916 | break; | - | ||||||||||||||||||||||||
917 | - | |||||||||||||||||||||||||
918 | --pos; | - | ||||||||||||||||||||||||
919 | } | - | ||||||||||||||||||||||||
920 | info = info.mid(pos + 1); | - | ||||||||||||||||||||||||
921 | - | |||||||||||||||||||||||||
922 | // remove trailing '*', '&' that are part of the return argument | - | ||||||||||||||||||||||||
923 | while ((info.at(0) == '*') | - | ||||||||||||||||||||||||
924 | || (info.at(0) == '&')) | - | ||||||||||||||||||||||||
925 | info = info.mid(1); | - | ||||||||||||||||||||||||
926 | - | |||||||||||||||||||||||||
927 | // we have the full function name now. | - | ||||||||||||||||||||||||
928 | // clean up the templates | - | ||||||||||||||||||||||||
929 | while ((pos = info.lastIndexOf('>')) != -1) { | - | ||||||||||||||||||||||||
930 | if (!info.contains('<')) | - | ||||||||||||||||||||||||
931 | break; | - | ||||||||||||||||||||||||
932 | - | |||||||||||||||||||||||||
933 | // find the matching close | - | ||||||||||||||||||||||||
934 | int end = pos; | - | ||||||||||||||||||||||||
935 | templatecount = 1; | - | ||||||||||||||||||||||||
936 | --pos; | - | ||||||||||||||||||||||||
937 | while (pos && templatecount) { | - | ||||||||||||||||||||||||
938 | char c = info.at(pos); | - | ||||||||||||||||||||||||
939 | if (c == '>') | - | ||||||||||||||||||||||||
940 | ++templatecount; | - | ||||||||||||||||||||||||
941 | else if (c == '<') | - | ||||||||||||||||||||||||
942 | --templatecount; | - | ||||||||||||||||||||||||
943 | --pos; | - | ||||||||||||||||||||||||
944 | } | - | ||||||||||||||||||||||||
945 | ++pos; | - | ||||||||||||||||||||||||
946 | info.remove(pos, end - pos + 1); | - | ||||||||||||||||||||||||
947 | } | - | ||||||||||||||||||||||||
948 | - | |||||||||||||||||||||||||
949 | return info; | - | ||||||||||||||||||||||||
950 | } | - | ||||||||||||||||||||||||
951 | - | |||||||||||||||||||||||||
952 | // tokens as recognized in QT_MESSAGE_PATTERN | - | ||||||||||||||||||||||||
953 | static const char categoryTokenC[] = "%{category}"; | - | ||||||||||||||||||||||||
954 | static const char typeTokenC[] = "%{type}"; | - | ||||||||||||||||||||||||
955 | static const char messageTokenC[] = "%{message}"; | - | ||||||||||||||||||||||||
956 | static const char fileTokenC[] = "%{file}"; | - | ||||||||||||||||||||||||
957 | static const char lineTokenC[] = "%{line}"; | - | ||||||||||||||||||||||||
958 | static const char functionTokenC[] = "%{function}"; | - | ||||||||||||||||||||||||
959 | static const char pidTokenC[] = "%{pid}"; | - | ||||||||||||||||||||||||
960 | static const char appnameTokenC[] = "%{appname}"; | - | ||||||||||||||||||||||||
961 | static const char threadidTokenC[] = "%{threadid}"; | - | ||||||||||||||||||||||||
962 | static const char qthreadptrTokenC[] = "%{qthreadptr}"; | - | ||||||||||||||||||||||||
963 | static const char timeTokenC[] = "%{time"; //not a typo: this command has arguments | - | ||||||||||||||||||||||||
964 | static const char backtraceTokenC[] = "%{backtrace"; //ditto | - | ||||||||||||||||||||||||
965 | static const char ifCategoryTokenC[] = "%{if-category}"; | - | ||||||||||||||||||||||||
966 | static const char ifDebugTokenC[] = "%{if-debug}"; | - | ||||||||||||||||||||||||
967 | static const char ifInfoTokenC[] = "%{if-info}"; | - | ||||||||||||||||||||||||
968 | static const char ifWarningTokenC[] = "%{if-warning}"; | - | ||||||||||||||||||||||||
969 | static const char ifCriticalTokenC[] = "%{if-critical}"; | - | ||||||||||||||||||||||||
970 | static const char ifFatalTokenC[] = "%{if-fatal}"; | - | ||||||||||||||||||||||||
971 | static const char endifTokenC[] = "%{endif}"; | - | ||||||||||||||||||||||||
972 | static const char emptyTokenC[] = ""; | - | ||||||||||||||||||||||||
973 | - | |||||||||||||||||||||||||
974 | static const char defaultPattern[] = "%{if-category}%{category}: %{endif}%{message}"; | - | ||||||||||||||||||||||||
975 | - | |||||||||||||||||||||||||
976 | - | |||||||||||||||||||||||||
977 | struct QMessagePattern { | - | ||||||||||||||||||||||||
978 | QMessagePattern(); | - | ||||||||||||||||||||||||
979 | ~QMessagePattern(); | - | ||||||||||||||||||||||||
980 | - | |||||||||||||||||||||||||
981 | void setPattern(const QString &pattern); | - | ||||||||||||||||||||||||
982 | - | |||||||||||||||||||||||||
983 | // 0 terminated arrays of literal tokens / literal or placeholder tokens | - | ||||||||||||||||||||||||
984 | const char **literals; | - | ||||||||||||||||||||||||
985 | const char **tokens; | - | ||||||||||||||||||||||||
986 | QList<QString> timeArgs; // timeFormats in sequence of %{time | - | ||||||||||||||||||||||||
987 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
988 | QElapsedTimer timer; | - | ||||||||||||||||||||||||
989 | #endif | - | ||||||||||||||||||||||||
990 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
991 | struct BacktraceParams { | - | ||||||||||||||||||||||||
992 | QString backtraceSeparator; | - | ||||||||||||||||||||||||
993 | int backtraceDepth; | - | ||||||||||||||||||||||||
994 | }; | - | ||||||||||||||||||||||||
995 | QVector<BacktraceParams> backtraceArgs; // backtrace argumens in sequence of %{backtrace | - | ||||||||||||||||||||||||
996 | #endif | - | ||||||||||||||||||||||||
997 | - | |||||||||||||||||||||||||
998 | bool fromEnvironment; | - | ||||||||||||||||||||||||
999 | static QBasicMutex mutex; | - | ||||||||||||||||||||||||
1000 | }; | - | ||||||||||||||||||||||||
1001 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
1002 | Q_DECLARE_TYPEINFO(QMessagePattern::BacktraceParams, Q_MOVABLE_TYPE); | - | ||||||||||||||||||||||||
1003 | #endif | - | ||||||||||||||||||||||||
1004 | - | |||||||||||||||||||||||||
1005 | QBasicMutex QMessagePattern::mutex; | - | ||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||
1007 | QMessagePattern::QMessagePattern() | - | ||||||||||||||||||||||||
1008 | : literals(0) | - | ||||||||||||||||||||||||
1009 | , tokens(0) | - | ||||||||||||||||||||||||
1010 | , fromEnvironment(false) | - | ||||||||||||||||||||||||
1011 | { | - | ||||||||||||||||||||||||
1012 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1013 | timer.start(); | - | ||||||||||||||||||||||||
1014 | #endif | - | ||||||||||||||||||||||||
1015 | const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN")); | - | ||||||||||||||||||||||||
1016 | if (envPattern.isEmpty()) { | - | ||||||||||||||||||||||||
1017 | setPattern(QLatin1String(defaultPattern)); | - | ||||||||||||||||||||||||
1018 | } else { | - | ||||||||||||||||||||||||
1019 | setPattern(envPattern); | - | ||||||||||||||||||||||||
1020 | fromEnvironment = true; | - | ||||||||||||||||||||||||
1021 | } | - | ||||||||||||||||||||||||
1022 | } | - | ||||||||||||||||||||||||
1023 | - | |||||||||||||||||||||||||
1024 | QMessagePattern::~QMessagePattern() | - | ||||||||||||||||||||||||
1025 | { | - | ||||||||||||||||||||||||
1026 | for (int i = 0; literals[i]; ++i) | - | ||||||||||||||||||||||||
1027 | delete [] literals[i]; | - | ||||||||||||||||||||||||
1028 | delete [] literals; | - | ||||||||||||||||||||||||
1029 | literals = 0; | - | ||||||||||||||||||||||||
1030 | delete [] tokens; | - | ||||||||||||||||||||||||
1031 | tokens = 0; | - | ||||||||||||||||||||||||
1032 | } | - | ||||||||||||||||||||||||
1033 | - | |||||||||||||||||||||||||
1034 | void QMessagePattern::setPattern(const QString &pattern) | - | ||||||||||||||||||||||||
1035 | { | - | ||||||||||||||||||||||||
1036 | if (literals) {
| 9-448 | ||||||||||||||||||||||||
1037 | for (int i = 0; literals[i]; ++i)
| 9-48 | ||||||||||||||||||||||||
1038 | delete [] literals[i]; executed 48 times by 2 tests: delete [] literals[i]; Executed by:
| 48 | ||||||||||||||||||||||||
1039 | delete [] literals; | - | ||||||||||||||||||||||||
1040 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||||||||
1041 | delete [] tokens; | - | ||||||||||||||||||||||||
1042 | timeArgs.clear(); | - | ||||||||||||||||||||||||
1043 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
1044 | backtraceArgs.clear(); | - | ||||||||||||||||||||||||
1045 | #endif | - | ||||||||||||||||||||||||
1046 | - | |||||||||||||||||||||||||
1047 | // scanner | - | ||||||||||||||||||||||||
1048 | QList<QString> lexemes; | - | ||||||||||||||||||||||||
1049 | QString lexeme; | - | ||||||||||||||||||||||||
1050 | bool inPlaceholder = false; | - | ||||||||||||||||||||||||
1051 | for (int i = 0; i < pattern.size(); ++i) {
| 457-21226 | ||||||||||||||||||||||||
1052 | const QChar c = pattern.at(i); | - | ||||||||||||||||||||||||
1053 | if ((c == QLatin1Char('%'))
| 1880-19346 | ||||||||||||||||||||||||
1054 | && !inPlaceholder) {
| 0-1880 | ||||||||||||||||||||||||
1055 | if ((i + 1 < pattern.size())
| 0-1880 | ||||||||||||||||||||||||
1056 | && pattern.at(i + 1) == QLatin1Char('{')) {
| 0-1880 | ||||||||||||||||||||||||
1057 | // beginning of placeholder | - | ||||||||||||||||||||||||
1058 | if (!lexeme.isEmpty()) {
| 528-1352 | ||||||||||||||||||||||||
1059 | lexemes.append(lexeme); | - | ||||||||||||||||||||||||
1060 | lexeme.clear(); | - | ||||||||||||||||||||||||
1061 | } executed 528 times by 106 tests: end of block Executed by:
| 528 | ||||||||||||||||||||||||
1062 | inPlaceholder = true; | - | ||||||||||||||||||||||||
1063 | } executed 1880 times by 106 tests: end of block Executed by:
| 1880 | ||||||||||||||||||||||||
1064 | } executed 1880 times by 106 tests: end of block Executed by:
| 1880 | ||||||||||||||||||||||||
1065 | - | |||||||||||||||||||||||||
1066 | lexeme.append(c); | - | ||||||||||||||||||||||||
1067 | - | |||||||||||||||||||||||||
1068 | if ((c == QLatin1Char('}') && inPlaceholder)) {
| 0-19346 | ||||||||||||||||||||||||
1069 | // end of placeholder | - | ||||||||||||||||||||||||
1070 | lexemes.append(lexeme); | - | ||||||||||||||||||||||||
1071 | lexeme.clear(); | - | ||||||||||||||||||||||||
1072 | inPlaceholder = false; | - | ||||||||||||||||||||||||
1073 | } executed 1880 times by 106 tests: end of block Executed by:
| 1880 | ||||||||||||||||||||||||
1074 | } executed 21226 times by 106 tests: end of block Executed by:
| 21226 | ||||||||||||||||||||||||
1075 | if (!lexeme.isEmpty())
| 13-444 | ||||||||||||||||||||||||
1076 | lexemes.append(lexeme); executed 13 times by 1 test: lexemes.append(lexeme); Executed by:
| 13 | ||||||||||||||||||||||||
1077 | - | |||||||||||||||||||||||||
1078 | // tokenizer | - | ||||||||||||||||||||||||
1079 | QVarLengthArray<const char*> literalsVar; | - | ||||||||||||||||||||||||
1080 | tokens = new const char*[lexemes.size() + 1]; | - | ||||||||||||||||||||||||
1081 | tokens[lexemes.size()] = 0; | - | ||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||
1083 | bool nestedIfError = false; | - | ||||||||||||||||||||||||
1084 | bool inIf = false; | - | ||||||||||||||||||||||||
1085 | QString error; | - | ||||||||||||||||||||||||
1086 | - | |||||||||||||||||||||||||
1087 | for (int i = 0; i < lexemes.size(); ++i) {
| 457-2421 | ||||||||||||||||||||||||
1088 | const QString lexeme = lexemes.at(i); | - | ||||||||||||||||||||||||
1089 | if (lexeme.startsWith(QLatin1String("%{"))
| 541-1880 | ||||||||||||||||||||||||
1090 | && lexeme.endsWith(QLatin1Char('}'))) {
| 0-1880 | ||||||||||||||||||||||||
1091 | // placeholder | - | ||||||||||||||||||||||||
1092 | if (lexeme == QLatin1String(typeTokenC)) {
| 3-1877 | ||||||||||||||||||||||||
1093 | tokens[i] = typeTokenC; | - | ||||||||||||||||||||||||
1094 | } else if (lexeme == QLatin1String(categoryTokenC)) executed 3 times by 2 tests: end of block Executed by:
| 3-1435 | ||||||||||||||||||||||||
1095 | tokens[i] = categoryTokenC; executed 442 times by 106 tests: tokens[i] = categoryTokenC; Executed by:
| 442 | ||||||||||||||||||||||||
1096 | else if (lexeme == QLatin1String(messageTokenC))
| 455-980 | ||||||||||||||||||||||||
1097 | tokens[i] = messageTokenC; executed 455 times by 106 tests: tokens[i] = messageTokenC; Executed by:
| 455 | ||||||||||||||||||||||||
1098 | else if (lexeme == QLatin1String(fileTokenC))
| 1-979 | ||||||||||||||||||||||||
1099 | tokens[i] = fileTokenC; executed 1 time by 1 test: tokens[i] = fileTokenC; Executed by:
| 1 | ||||||||||||||||||||||||
1100 | else if (lexeme == QLatin1String(lineTokenC))
| 2-977 | ||||||||||||||||||||||||
1101 | tokens[i] = lineTokenC; executed 2 times by 2 tests: tokens[i] = lineTokenC; Executed by:
| 2 | ||||||||||||||||||||||||
1102 | else if (lexeme == QLatin1String(functionTokenC))
| 2-975 | ||||||||||||||||||||||||
1103 | tokens[i] = functionTokenC; executed 2 times by 2 tests: tokens[i] = functionTokenC; Executed by:
| 2 | ||||||||||||||||||||||||
1104 | else if (lexeme == QLatin1String(pidTokenC))
| 1-974 | ||||||||||||||||||||||||
1105 | tokens[i] = pidTokenC; executed 1 time by 1 test: tokens[i] = pidTokenC; Executed by:
| 1 | ||||||||||||||||||||||||
1106 | else if (lexeme == QLatin1String(appnameTokenC))
| 1-973 | ||||||||||||||||||||||||
1107 | tokens[i] = appnameTokenC; executed 1 time by 1 test: tokens[i] = appnameTokenC; Executed by:
| 1 | ||||||||||||||||||||||||
1108 | else if (lexeme == QLatin1String(threadidTokenC))
| 1-972 | ||||||||||||||||||||||||
1109 | tokens[i] = threadidTokenC; executed 1 time by 1 test: tokens[i] = threadidTokenC; Executed by:
| 1 | ||||||||||||||||||||||||
1110 | else if (lexeme == QLatin1String(qthreadptrTokenC))
| 1-971 | ||||||||||||||||||||||||
1111 | tokens[i] = qthreadptrTokenC; executed 1 time by 1 test: tokens[i] = qthreadptrTokenC; Executed by:
| 1 | ||||||||||||||||||||||||
1112 | else if (lexeme.startsWith(QLatin1String(timeTokenC))) {
| 6-965 | ||||||||||||||||||||||||
1113 | tokens[i] = timeTokenC; | - | ||||||||||||||||||||||||
1114 | int spaceIdx = lexeme.indexOf(QChar::fromLatin1(' ')); | - | ||||||||||||||||||||||||
1115 | if (spaceIdx > 0)
| 0-6 | ||||||||||||||||||||||||
1116 | timeArgs.append(lexeme.mid(spaceIdx + 1, lexeme.length() - spaceIdx - 2)); executed 6 times by 1 test: timeArgs.append(lexeme.mid(spaceIdx + 1, lexeme.length() - spaceIdx - 2)); Executed by:
| 6 | ||||||||||||||||||||||||
1117 | else | - | ||||||||||||||||||||||||
1118 | timeArgs.append(QString()); never executed: timeArgs.append(QString()); | 0 | ||||||||||||||||||||||||
1119 | } else if (lexeme.startsWith(QLatin1String(backtraceTokenC))) {
| 2-963 | ||||||||||||||||||||||||
1120 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
1121 | tokens[i] = backtraceTokenC; | - | ||||||||||||||||||||||||
1122 | QString backtraceSeparator = QStringLiteral("|"); | - | ||||||||||||||||||||||||
1123 | int backtraceDepth = 5; | - | ||||||||||||||||||||||||
1124 | QRegularExpression depthRx(QStringLiteral(" depth=(?|\"([^\"]*)\"|([^ }]*))")); executed 2 times by 1 test: return qstring_literal_temp; Executed by:
| 2 | ||||||||||||||||||||||||
1125 | QRegularExpression separatorRx(QStringLiteral(" separator=(?|\"([^\"]*)\"|([^ }]*))")); executed 2 times by 1 test: return qstring_literal_temp; Executed by:
| 2 | ||||||||||||||||||||||||
1126 | QRegularExpressionMatch m = depthRx.match(lexeme); | - | ||||||||||||||||||||||||
1127 | if (m.hasMatch()) {
| 1 | ||||||||||||||||||||||||
1128 | int depth = m.capturedRef(1).toInt(); | - | ||||||||||||||||||||||||
1129 | if (depth <= 0)
| 0-1 | ||||||||||||||||||||||||
1130 | error += QStringLiteralQLatin1String("QT_MESSAGE_PATTERN: %{backtrace} depth must be a number greater than 0\n"); never executed: error += QLatin1String("QT_MESSAGE_PATTERN: %{backtrace} depth must be a number greater than 0\n"); | 0 | ||||||||||||||||||||||||
1131 | else | - | ||||||||||||||||||||||||
1132 | backtraceDepth = depth; executed 1 time by 1 test: backtraceDepth = depth; Executed by:
| 1 | ||||||||||||||||||||||||
1133 | } | - | ||||||||||||||||||||||||
1134 | m = separatorRx.match(lexeme); | - | ||||||||||||||||||||||||
1135 | if (m.hasMatch())
| 1 | ||||||||||||||||||||||||
1136 | backtraceSeparator = m.captured(1); executed 1 time by 1 test: backtraceSeparator = m.captured(1); Executed by:
| 1 | ||||||||||||||||||||||||
1137 | BacktraceParams backtraceParams; | - | ||||||||||||||||||||||||
1138 | backtraceParams.backtraceDepth = backtraceDepth; | - | ||||||||||||||||||||||||
1139 | backtraceParams.backtraceSeparator = backtraceSeparator; | - | ||||||||||||||||||||||||
1140 | backtraceArgs.append(backtraceParams); | - | ||||||||||||||||||||||||
1141 | #else | - | ||||||||||||||||||||||||
1142 | error += QStringLiteralQLatin1String("QT_MESSAGE_PATTERN: %{backtrace} is not supported by this Qt build\n"); | - | ||||||||||||||||||||||||
1143 | tokens[i] = ""; | - | ||||||||||||||||||||||||
1144 | #endif | - | ||||||||||||||||||||||||
1145 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1146 | - | |||||||||||||||||||||||||
1147 | #define IF_TOKEN(LEVEL) \ | - | ||||||||||||||||||||||||
1148 | else if (lexeme == QLatin1String(LEVEL)) { \ | - | ||||||||||||||||||||||||
1149 | if (inIf) \ | - | ||||||||||||||||||||||||
1150 | nestedIfError = true; \ | - | ||||||||||||||||||||||||
1151 | tokens[i] = LEVEL; \ | - | ||||||||||||||||||||||||
1152 | inIf = true; \ | - | ||||||||||||||||||||||||
1153 | } | - | ||||||||||||||||||||||||
1154 | IF_TOKEN(ifCategoryTokenC) never executed: nestedIfError = true; executed 442 times by 106 tests: end of block Executed by:
| 0-521 | ||||||||||||||||||||||||
1155 | IF_TOKEN(ifDebugTokenC) never executed: nestedIfError = true; executed 9 times by 2 tests: end of block Executed by:
| 0-512 | ||||||||||||||||||||||||
1156 | IF_TOKEN(ifInfoTokenC) never executed: nestedIfError = true; executed 6 times by 1 test: end of block Executed by:
| 0-506 | ||||||||||||||||||||||||
1157 | IF_TOKEN(ifWarningTokenC) executed 1 time by 1 test: nestedIfError = true; Executed by:
executed 10 times by 2 tests: end of block Executed by:
| 1-496 | ||||||||||||||||||||||||
1158 | IF_TOKEN(ifCriticalTokenC) never executed: nestedIfError = true; executed 7 times by 2 tests: end of block Executed by:
| 0-489 | ||||||||||||||||||||||||
1159 | IF_TOKEN(ifFatalTokenC) never executed: nestedIfError = true; executed 7 times by 2 tests: end of block Executed by:
| 0-482 | ||||||||||||||||||||||||
1160 | #undef IF_TOKEN | - | ||||||||||||||||||||||||
1161 | else if (lexeme == QLatin1String(endifTokenC)) {
| 2-480 | ||||||||||||||||||||||||
1162 | tokens[i] = endifTokenC; | - | ||||||||||||||||||||||||
1163 | if (!inIf && !nestedIfError)
| 0-479 | ||||||||||||||||||||||||
1164 | error += QStringLiteralQLatin1String("QT_MESSAGE_PATTERN: %{endif} without an %{if-*}\n"); executed 1 time by 1 test: error += QLatin1String("QT_MESSAGE_PATTERN: %{endif} without an %{if-*}\n"); Executed by:
| 1 | ||||||||||||||||||||||||
1165 | inIf = false; | - | ||||||||||||||||||||||||
1166 | } else { executed 480 times by 106 tests: end of block Executed by:
| 480 | ||||||||||||||||||||||||
1167 | tokens[i] = emptyTokenC; | - | ||||||||||||||||||||||||
1168 | error += QStringLiteral("QT_MESSAGE_PATTERN: Unknown placeholder %1\n") executed 2 times by 1 test: return qstring_literal_temp; Executed by:
| 2 | ||||||||||||||||||||||||
1169 | .arg(lexeme); | - | ||||||||||||||||||||||||
1170 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
1171 | } else { | - | ||||||||||||||||||||||||
1172 | char *literal = new char[lexeme.size() + 1]; | - | ||||||||||||||||||||||||
1173 | strncpy(literal, lexeme.toLatin1().constData(), lexeme.size()); | - | ||||||||||||||||||||||||
1174 | literal[lexeme.size()] = '\0'; | - | ||||||||||||||||||||||||
1175 | literalsVar.append(literal); | - | ||||||||||||||||||||||||
1176 | tokens[i] = literal; | - | ||||||||||||||||||||||||
1177 | } executed 541 times by 106 tests: end of block Executed by:
| 541 | ||||||||||||||||||||||||
1178 | } | - | ||||||||||||||||||||||||
1179 | if (nestedIfError)
| 1-456 | ||||||||||||||||||||||||
1180 | error += QStringLiteralQLatin1String("QT_MESSAGE_PATTERN: %{if-*} cannot be nested\n"); executed 1 time by 1 test: error += QLatin1String("QT_MESSAGE_PATTERN: %{if-*} cannot be nested\n"); Executed by:
| 1 | ||||||||||||||||||||||||
1181 | else if (inIf)
| 1-455 | ||||||||||||||||||||||||
1182 | error += QStringLiteralQLatin1String("QT_MESSAGE_PATTERN: missing %{endif}\n"); executed 1 time by 1 test: error += QLatin1String("QT_MESSAGE_PATTERN: missing %{endif}\n"); Executed by:
| 1 | ||||||||||||||||||||||||
1183 | if (!error.isEmpty()) {
| 3-454 | ||||||||||||||||||||||||
1184 | #if defined(Q_OS_WINCE) || defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
1185 | OutputDebugString(reinterpret_cast<const wchar_t*>(error.utf16())); | - | ||||||||||||||||||||||||
1186 | if (0) | - | ||||||||||||||||||||||||
1187 | #elif defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) | - | ||||||||||||||||||||||||
1188 | if (!qt_logging_to_console()) { | - | ||||||||||||||||||||||||
1189 | OutputDebugString(reinterpret_cast<const wchar_t*>(error.utf16())); | - | ||||||||||||||||||||||||
1190 | } else | - | ||||||||||||||||||||||||
1191 | #endif | - | ||||||||||||||||||||||||
1192 | { | - | ||||||||||||||||||||||||
1193 | fprintf(stderr, "%s", error.toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
1194 | fflush(stderr); | - | ||||||||||||||||||||||||
1195 | } | - | ||||||||||||||||||||||||
1196 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||||||||
1197 | literals = new const char*[literalsVar.size() + 1]; | - | ||||||||||||||||||||||||
1198 | literals[literalsVar.size()] = 0; | - | ||||||||||||||||||||||||
1199 | memcpy(literals, literalsVar.constData(), literalsVar.size() * sizeof(const char*)); | - | ||||||||||||||||||||||||
1200 | } executed 457 times by 106 tests: end of block Executed by:
| 457 | ||||||||||||||||||||||||
1201 | - | |||||||||||||||||||||||||
1202 | #if defined(QLOGGING_HAVE_BACKTRACE) && !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
1203 | // make sure the function has "Message" in the name so the function is removed | - | ||||||||||||||||||||||||
1204 | - | |||||||||||||||||||||||||
1205 | #if ((defined(Q_CC_GNU) && defined(QT_COMPILER_SUPPORTS_SIMD_ALWAYS)) || QT_HAS_ATTRIBUTE(optimize)) \ | - | ||||||||||||||||||||||||
1206 | && !defined(Q_CC_INTEL) | - | ||||||||||||||||||||||||
1207 | // force skipping the frame pointer, to save the backtrace() function some work | - | ||||||||||||||||||||||||
1208 | __attribute__((optimize("omit-frame-pointer"))) | - | ||||||||||||||||||||||||
1209 | #endif | - | ||||||||||||||||||||||||
1210 | static QStringList backtraceFramesForLogMessage(int frameCount) | - | ||||||||||||||||||||||||
1211 | { | - | ||||||||||||||||||||||||
1212 | QStringList result; | - | ||||||||||||||||||||||||
1213 | if (frameCount == 0)
| 0-16 | ||||||||||||||||||||||||
1214 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
1215 | - | |||||||||||||||||||||||||
1216 | // The results of backtrace_symbols looks like this: | - | ||||||||||||||||||||||||
1217 | // /lib/libc.so.6(__libc_start_main+0xf3) [0x4a937413] | - | ||||||||||||||||||||||||
1218 | // The offset and function name are optional. | - | ||||||||||||||||||||||||
1219 | // This regexp tries to extract the library name (without the path) and the function name. | - | ||||||||||||||||||||||||
1220 | // This code is protected by QMessagePattern::mutex so it is thread safe on all compilers | - | ||||||||||||||||||||||||
1221 | static QRegularExpression rx(QStringLiteral("^(?:[^(]*/)?([^(/]+)\\(([^+]*)(?:[\\+[a-f0-9x]*)?\\) \\[[a-f0-9x]*\\]$"), | - | ||||||||||||||||||||||||
1222 | QRegularExpression::OptimizeOnFirstUsageOption); | - | ||||||||||||||||||||||||
1223 | - | |||||||||||||||||||||||||
1224 | QVarLengthArray<void*, 32> buffer(7 + frameCount); | - | ||||||||||||||||||||||||
1225 | int n = backtrace(buffer.data(), buffer.size()); | - | ||||||||||||||||||||||||
1226 | if (n > 0) {
| 0-16 | ||||||||||||||||||||||||
1227 | int numberPrinted = 0; | - | ||||||||||||||||||||||||
1228 | for (int i = 0; i < n && numberPrinted < frameCount; ++i) {
| 0-156 | ||||||||||||||||||||||||
1229 | QScopedPointer<char*, QScopedPointerPodDeleter> strings(backtrace_symbols(buffer.data() + i, 1)); | - | ||||||||||||||||||||||||
1230 | QString trace = QString::fromLatin1(strings.data()[0]); | - | ||||||||||||||||||||||||
1231 | QRegularExpressionMatch m = rx.match(trace); | - | ||||||||||||||||||||||||
1232 | if (m.hasMatch()) {
| 0-156 | ||||||||||||||||||||||||
1233 | QString library = m.captured(1); | - | ||||||||||||||||||||||||
1234 | QString function = m.captured(2); | - | ||||||||||||||||||||||||
1235 | - | |||||||||||||||||||||||||
1236 | // skip the trace from QtCore that are because of the qDebug itself | - | ||||||||||||||||||||||||
1237 |
| 16-128 | ||||||||||||||||||||||||
1238 | && (function.isEmpty() || function.contains(QLatin1String("Message"), Qt::CaseInsensitive)
| 4-76 | ||||||||||||||||||||||||
1239 | || function.contains(QLatin1String("QDebug")))) {
| 0-4 | ||||||||||||||||||||||||
1240 | continue; executed 112 times by 1 test: continue; Executed by:
| 112 | ||||||||||||||||||||||||
1241 | } | - | ||||||||||||||||||||||||
1242 | - | |||||||||||||||||||||||||
1243 | if (function.startsWith(QLatin1String("_Z"))) {
| 8-36 | ||||||||||||||||||||||||
1244 | QScopedPointer<char, QScopedPointerPodDeleter> demangled( | - | ||||||||||||||||||||||||
1245 | abi::__cxa_demangle(function.toUtf8(), 0, 0, 0)); | - | ||||||||||||||||||||||||
1246 | if (demangled)
| 0-8 | ||||||||||||||||||||||||
1247 | function = QString::fromUtf8(qCleanupFuncinfo(demangled.data())); executed 8 times by 1 test: function = QString::fromUtf8(qCleanupFuncinfo(demangled.data())); Executed by:
| 8 | ||||||||||||||||||||||||
1248 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||||||||
1249 | - | |||||||||||||||||||||||||
1250 | if (function.isEmpty()) {
| 10-34 | ||||||||||||||||||||||||
1251 | result.append(QLatin1Char('?') + library + QLatin1Char('?')); | - | ||||||||||||||||||||||||
1252 | } else { executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||||||||
1253 | result.append(function); | - | ||||||||||||||||||||||||
1254 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||||||||
1255 | } else { | - | ||||||||||||||||||||||||
1256 | if (numberPrinted == 0) {
| 0 | ||||||||||||||||||||||||
1257 | // innermost, unknown frames are usually the logging framework itself | - | ||||||||||||||||||||||||
1258 | never executed: continue;continue; never executed: continue; | 0 | ||||||||||||||||||||||||
1259 | } | - | ||||||||||||||||||||||||
1260 | result.append(QStringLiteral("???")); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||||||||
1261 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1262 | numberPrinted++; | - | ||||||||||||||||||||||||
1263 | } executed 44 times by 1 test: end of block Executed by:
| 44 | ||||||||||||||||||||||||
1264 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||||||||||||||
1265 | return result; executed 16 times by 1 test: return result; Executed by:
| 16 | ||||||||||||||||||||||||
1266 | } | - | ||||||||||||||||||||||||
1267 | - | |||||||||||||||||||||||||
1268 | static QString formatBacktraceForLogMessage(const QMessagePattern::BacktraceParams backtraceParams, | - | ||||||||||||||||||||||||
1269 | const char *function) | - | ||||||||||||||||||||||||
1270 | { | - | ||||||||||||||||||||||||
1271 | QString backtraceSeparator = backtraceParams.backtraceSeparator; | - | ||||||||||||||||||||||||
1272 | int backtraceDepth = backtraceParams.backtraceDepth; | - | ||||||||||||||||||||||||
1273 | - | |||||||||||||||||||||||||
1274 | QStringList frames = backtraceFramesForLogMessage(backtraceDepth); | - | ||||||||||||||||||||||||
1275 | if (frames.isEmpty())
| 0-16 | ||||||||||||||||||||||||
1276 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | // if the first frame is unknown, replace it with the context function | - | ||||||||||||||||||||||||
1279 |
| 0-16 | ||||||||||||||||||||||||
1280 | frames[0] = QString::fromUtf8(qCleanupFuncinfo(function)); never executed: frames[0] = QString::fromUtf8(qCleanupFuncinfo(function)); | 0 | ||||||||||||||||||||||||
1281 | - | |||||||||||||||||||||||||
1282 | return frames.join(backtraceSeparator); executed 16 times by 1 test: return frames.join(backtraceSeparator); Executed by:
| 16 | ||||||||||||||||||||||||
1283 | } | - | ||||||||||||||||||||||||
1284 | #endif // QLOGGING_HAVE_BACKTRACE && !QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1285 | - | |||||||||||||||||||||||||
1286 | #if defined(QT_USE_SLOG2) | - | ||||||||||||||||||||||||
1287 | #ifndef QT_LOG_CODE | - | ||||||||||||||||||||||||
1288 | #define QT_LOG_CODE 9000 | - | ||||||||||||||||||||||||
1289 | #endif | - | ||||||||||||||||||||||||
1290 | - | |||||||||||||||||||||||||
1291 | static void slog2_default_handler(QtMsgType msgType, const char *message) | - | ||||||||||||||||||||||||
1292 | { | - | ||||||||||||||||||||||||
1293 | if (slog2_set_default_buffer((slog2_buffer_t)-1) == 0) { | - | ||||||||||||||||||||||||
1294 | slog2_buffer_set_config_t buffer_config; | - | ||||||||||||||||||||||||
1295 | slog2_buffer_t buffer_handle; | - | ||||||||||||||||||||||||
1296 | - | |||||||||||||||||||||||||
1297 | buffer_config.buffer_set_name = __progname; | - | ||||||||||||||||||||||||
1298 | buffer_config.num_buffers = 1; | - | ||||||||||||||||||||||||
1299 | buffer_config.verbosity_level = SLOG2_DEBUG1; | - | ||||||||||||||||||||||||
1300 | buffer_config.buffer_config[0].buffer_name = "default"; | - | ||||||||||||||||||||||||
1301 | buffer_config.buffer_config[0].num_pages = 8; | - | ||||||||||||||||||||||||
1302 | - | |||||||||||||||||||||||||
1303 | if (slog2_register(&buffer_config, &buffer_handle, 0) == -1) { | - | ||||||||||||||||||||||||
1304 | fprintf(stderr, "Error registering slogger2 buffer!\n"); | - | ||||||||||||||||||||||||
1305 | fprintf(stderr, "%s", message); | - | ||||||||||||||||||||||||
1306 | fflush(stderr); | - | ||||||||||||||||||||||||
1307 | return; | - | ||||||||||||||||||||||||
1308 | } | - | ||||||||||||||||||||||||
1309 | - | |||||||||||||||||||||||||
1310 | // Set as the default buffer | - | ||||||||||||||||||||||||
1311 | slog2_set_default_buffer(buffer_handle); | - | ||||||||||||||||||||||||
1312 | } | - | ||||||||||||||||||||||||
1313 | int severity; | - | ||||||||||||||||||||||||
1314 | //Determines the severity level | - | ||||||||||||||||||||||||
1315 | switch (msgType) { | - | ||||||||||||||||||||||||
1316 | case QtDebugMsg: | - | ||||||||||||||||||||||||
1317 | severity = SLOG2_DEBUG1; | - | ||||||||||||||||||||||||
1318 | break; | - | ||||||||||||||||||||||||
1319 | case QtInfoMsg: | - | ||||||||||||||||||||||||
1320 | severity = SLOG2_INFO; | - | ||||||||||||||||||||||||
1321 | break; | - | ||||||||||||||||||||||||
1322 | case QtWarningMsg: | - | ||||||||||||||||||||||||
1323 | severity = SLOG2_NOTICE; | - | ||||||||||||||||||||||||
1324 | break; | - | ||||||||||||||||||||||||
1325 | case QtCriticalMsg: | - | ||||||||||||||||||||||||
1326 | severity = SLOG2_WARNING; | - | ||||||||||||||||||||||||
1327 | break; | - | ||||||||||||||||||||||||
1328 | case QtFatalMsg: | - | ||||||||||||||||||||||||
1329 | severity = SLOG2_ERROR; | - | ||||||||||||||||||||||||
1330 | break; | - | ||||||||||||||||||||||||
1331 | } | - | ||||||||||||||||||||||||
1332 | //writes to the slog2 buffer | - | ||||||||||||||||||||||||
1333 | slog2c(NULL, QT_LOG_CODE, severity, message); | - | ||||||||||||||||||||||||
1334 | } | - | ||||||||||||||||||||||||
1335 | #endif // QT_USE_SLOG2 | - | ||||||||||||||||||||||||
1336 | - | |||||||||||||||||||||||||
1337 | Q_GLOBAL_STATIC(QMessagePattern, qMessagePattern) | - | ||||||||||||||||||||||||
1338 | - | |||||||||||||||||||||||||
1339 | /*! | - | ||||||||||||||||||||||||
1340 | \relates <QtGlobal> | - | ||||||||||||||||||||||||
1341 | \since 5.4 | - | ||||||||||||||||||||||||
1342 | - | |||||||||||||||||||||||||
1343 | Generates a formatted string out of the \a type, \a context, \a str arguments. | - | ||||||||||||||||||||||||
1344 | - | |||||||||||||||||||||||||
1345 | qFormatLogMessage returns a QString that is formatted according to the current message pattern. | - | ||||||||||||||||||||||||
1346 | It can be used by custom message handlers to format output similar to Qt's default message | - | ||||||||||||||||||||||||
1347 | handler. | - | ||||||||||||||||||||||||
1348 | - | |||||||||||||||||||||||||
1349 | The function is thread-safe. | - | ||||||||||||||||||||||||
1350 | - | |||||||||||||||||||||||||
1351 | \sa qInstallMessageHandler(), qSetMessagePattern() | - | ||||||||||||||||||||||||
1352 | */ | - | ||||||||||||||||||||||||
1353 | QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str) | - | ||||||||||||||||||||||||
1354 | { | - | ||||||||||||||||||||||||
1355 | QString message; | - | ||||||||||||||||||||||||
1356 | - | |||||||||||||||||||||||||
1357 | QMutexLocker lock(&QMessagePattern::mutex); | - | ||||||||||||||||||||||||
1358 | - | |||||||||||||||||||||||||
1359 | QMessagePattern *pattern = qMessagePattern(); | - | ||||||||||||||||||||||||
1360 | if (!pattern) {
| 0-254286 | ||||||||||||||||||||||||
1361 | // after destruction of static QMessagePattern instance | - | ||||||||||||||||||||||||
1362 | message.append(str); | - | ||||||||||||||||||||||||
1363 | return message; never executed: return message; | 0 | ||||||||||||||||||||||||
1364 | } | - | ||||||||||||||||||||||||
1365 | - | |||||||||||||||||||||||||
1366 | bool skip = false; | - | ||||||||||||||||||||||||
1367 | - | |||||||||||||||||||||||||
1368 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1369 | int timeArgsIdx = 0; | - | ||||||||||||||||||||||||
1370 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
1371 | int backtraceArgsIdx = 0; | - | ||||||||||||||||||||||||
1372 | #endif | - | ||||||||||||||||||||||||
1373 | #endif | - | ||||||||||||||||||||||||
1374 | - | |||||||||||||||||||||||||
1375 | // we do not convert file, function, line literals to local encoding due to overhead | - | ||||||||||||||||||||||||
1376 | for (int i = 0; pattern->tokens[i] != 0; ++i) {
| 254286-1271809 | ||||||||||||||||||||||||
1377 | const char *token = pattern->tokens[i]; | - | ||||||||||||||||||||||||
1378 | if (token == endifTokenC) {
| 254276-1017533 | ||||||||||||||||||||||||
1379 | skip = false; | - | ||||||||||||||||||||||||
1380 | } else if (skip) { executed 254276 times by 106 tests: end of block Executed by:
| 254276-509094 | ||||||||||||||||||||||||
1381 | // we skip adding messages, but we have to iterate over | - | ||||||||||||||||||||||||
1382 | // timeArgsIdx and backtraceArgsIdx anyway | - | ||||||||||||||||||||||||
1383 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1384 | if (token == timeTokenC)
| 10-508429 | ||||||||||||||||||||||||
1385 | timeArgsIdx++; executed 10 times by 1 test: timeArgsIdx++; Executed by:
| 10 | ||||||||||||||||||||||||
1386 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
1387 | else if (token == backtraceTokenC)
| 0-508429 | ||||||||||||||||||||||||
1388 | backtraceArgsIdx++; never executed: backtraceArgsIdx++; | 0 | ||||||||||||||||||||||||
1389 | #endif | - | ||||||||||||||||||||||||
1390 | #endif | - | ||||||||||||||||||||||||
1391 | } else if (token == messageTokenC) { executed 508439 times by 106 tests: end of block Executed by:
| 254276-508439 | ||||||||||||||||||||||||
1392 | message.append(str); | - | ||||||||||||||||||||||||
1393 | } else if (token == categoryTokenC) { executed 254276 times by 106 tests: end of block Executed by:
| 3-254815 | ||||||||||||||||||||||||
1394 | message.append(QLatin1String(context.category)); | - | ||||||||||||||||||||||||
1395 | } else if (token == typeTokenC) { executed 3 times by 3 tests: end of block Executed by:
| 3-254801 | ||||||||||||||||||||||||
1396 | switch (type) { | - | ||||||||||||||||||||||||
1397 | case QtDebugMsg: message.append(QLatin1String("debug")); break; executed 6 times by 2 tests: break; Executed by:
executed 6 times by 2 tests: case QtDebugMsg: Executed by:
| 6 | ||||||||||||||||||||||||
1398 | case QtInfoMsg: message.append(QLatin1String("info")); break; executed 2 times by 1 test: break; Executed by:
executed 2 times by 1 test: case QtInfoMsg: Executed by:
| 2 | ||||||||||||||||||||||||
1399 | case QtWarningMsg: message.append(QLatin1String("warning")); break; executed 4 times by 1 test: break; Executed by:
executed 4 times by 1 test: case QtWarningMsg: Executed by:
| 4 | ||||||||||||||||||||||||
1400 | case QtCriticalMsg:message.append(QLatin1String("critical")); break; executed 2 times by 1 test: break; Executed by:
executed 2 times by 1 test: case QtCriticalMsg: Executed by:
| 2 | ||||||||||||||||||||||||
1401 | case QtFatalMsg: message.append(QLatin1String("fatal")); break; never executed: break; never executed: case QtFatalMsg: | 0 | ||||||||||||||||||||||||
1402 | } | - | ||||||||||||||||||||||||
1403 | } else if (token == fileTokenC) { executed 14 times by 2 tests: end of block Executed by:
| 1-254800 | ||||||||||||||||||||||||
1404 | if (context.file)
| 0-1 | ||||||||||||||||||||||||
1405 | message.append(QLatin1String(context.file)); executed 1 time by 1 test: message.append(QLatin1String(context.file)); Executed by:
| 1 | ||||||||||||||||||||||||
1406 | else | - | ||||||||||||||||||||||||
1407 | message.append(QLatin1String("unknown")); never executed: message.append(QLatin1String("unknown")); | 0 | ||||||||||||||||||||||||
1408 | } else if (token == lineTokenC) {
| 9-254791 | ||||||||||||||||||||||||
1409 | message.append(QString::number(context.line)); | - | ||||||||||||||||||||||||
1410 | } else if (token == functionTokenC) { executed 9 times by 2 tests: end of block Executed by:
| 9-254782 | ||||||||||||||||||||||||
1411 | if (context.function)
| 0-9 | ||||||||||||||||||||||||
1412 | message.append(QString::fromLatin1(qCleanupFuncinfo(context.function))); executed 9 times by 2 tests: message.append(QString::fromLatin1(qCleanupFuncinfo(context.function))); Executed by:
| 9 | ||||||||||||||||||||||||
1413 | else | - | ||||||||||||||||||||||||
1414 | message.append(QLatin1String("unknown")); never executed: message.append(QLatin1String("unknown")); | 0 | ||||||||||||||||||||||||
1415 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1416 | } else if (token == pidTokenC) {
| 8-254774 | ||||||||||||||||||||||||
1417 | message.append(QString::number(QCoreApplication::applicationPid())); | - | ||||||||||||||||||||||||
1418 | } else if (token == appnameTokenC) { executed 8 times by 1 test: end of block Executed by:
| 8-254766 | ||||||||||||||||||||||||
1419 | message.append(QCoreApplication::applicationName()); | - | ||||||||||||||||||||||||
1420 | } else if (token == threadidTokenC) { executed 8 times by 1 test: end of block Executed by:
| 8-254758 | ||||||||||||||||||||||||
1421 | // print the TID as decimal | - | ||||||||||||||||||||||||
1422 | message.append(QString::number(qt_gettid())); | - | ||||||||||||||||||||||||
1423 | } else if (token == qthreadptrTokenC) { executed 8 times by 1 test: end of block Executed by:
| 8-254750 | ||||||||||||||||||||||||
1424 | message.append(QLatin1String("0x")); | - | ||||||||||||||||||||||||
1425 | message.append(QString::number(qlonglong(QThread::currentThread()->currentThread()), 16)); | - | ||||||||||||||||||||||||
1426 | #ifdef QLOGGING_HAVE_BACKTRACE | - | ||||||||||||||||||||||||
1427 | } else if (token == backtraceTokenC) { executed 8 times by 1 test: end of block Executed by:
| 8-254734 | ||||||||||||||||||||||||
1428 | QMessagePattern::BacktraceParams backtraceParams = pattern->backtraceArgs.at(backtraceArgsIdx); | - | ||||||||||||||||||||||||
1429 | QString backtraceSeparator = backtraceParams.backtraceSeparator; | - | ||||||||||||||||||||||||
int backtraceDepth = backtraceParams.backtraceDepth;backtraceArgsIdx++; | ||||||||||||||||||||||||||
1430 | QVarLengthArray<void*, 32> buffer(7 + backtraceDepth); | - | ||||||||||||||||||||||||
int n = backtrace(buffer.data(), buffer.size()); | ||||||||||||||||||||||||||
if (n > 0) { | ||||||||||||||||||||||||||
int numberPrinted = 0; | ||||||||||||||||||||||||||
for (int i = 0; i < n && numberPrinted < backtraceDepth; ++i) { | ||||||||||||||||||||||||||
QScopedPointer<char*, QScopedPointerPodDeleter> strings(backtrace_symbols(buffer.data() + i, 1)); | ||||||||||||||||||||||||||
QString trace = QString::fromLatin1(strings.data()[0]); | ||||||||||||||||||||||||||
static QRegularExpression rx(QStringLiteral("^(?:[^(]*/)?([^(/]+)\\(([^+]*)(?:[\\+[a-f0-9x]*)?\\) \\[[a-f0-9x]*\\]$"), | ||||||||||||||||||||||||||
QRegularExpression::OptimizeOnFirstUsageOption); | ||||||||||||||||||||||||||
QRegularExpressionMatch m = rx.match(trace); | ||||||||||||||||||||||||||
if (m.hasMatch()) { | ||||||||||||||||||||||||||
QString library = m.captured(1); | ||||||||||||||||||||||||||
QString function = m.captured(2); | ||||||||||||||||||||||||||
if (!numberPrinted && library.contains(QLatin1String("Qt5Core")) | ||||||||||||||||||||||||||
&& (function.isEmpty() || function.contains(QLatin1String("Message"), Qt::CaseInsensitive) | ||||||||||||||||||||||||||
|| function.contains(QLatin1String("QDebug")))) { | ||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
if (function.startsWith(QLatin1String("_Z"))) { | ||||||||||||||||||||||||||
QScopedPointer<char, QScopedPointerPodDeleter> demangled( | ||||||||||||||||||||||||||
abi::__cxa_demangle(function.toUtf8(), 0, 0, 0)); | ||||||||||||||||||||||||||
if (demangled) | ||||||||||||||||||||||||||
function = QString::fromUtf8(qCleanupFuncinfo(demangled.data())); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
if (numberPrinted > 0)message.append(backtraceSeparator); | ||||||||||||||||||||||||||
if (function.isEmpty()) { | ||||||||||||||||||||||||||
if (numberPrinted == 0 && context.function) | ||||||||||||||||||||||||||
message += QString::fromUtf8(qCleanupFuncinfoformatBacktraceForLogMessage(backtraceParams, context.function));else | ||||||||||||||||||||||||||
message += QLatin1Char('?') + library + QLatin1Char('?'); | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
message += function; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
if (numberPrinted == 0) | ||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||
message += backtraceSeparator + QLatin1String("???"); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
numberPrinted++; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
1431 | #endif | - | ||||||||||||||||||||||||
1432 | } else if (token == timeTokenC) { executed 16 times by 1 test: end of block Executed by:
| 16-254696 | ||||||||||||||||||||||||
1433 | QString timeFormat = pattern->timeArgs.at(timeArgsIdx); | - | ||||||||||||||||||||||||
1434 | timeArgsIdx++; | - | ||||||||||||||||||||||||
1435 | if (timeFormat == QLatin1String("process")) {
| 8-30 | ||||||||||||||||||||||||
1436 | quint64 ms = pattern->timer.elapsed(); | - | ||||||||||||||||||||||||
1437 | message.append(QString::asprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000))); | - | ||||||||||||||||||||||||
1438 | } else if (timeFormat == QLatin1String("boot")) { executed 8 times by 1 test: end of block Executed by:
| 0-30 | ||||||||||||||||||||||||
1439 | // just print the milliseconds since the elapsed timer reference | - | ||||||||||||||||||||||||
1440 | // like the Linux kernel does | - | ||||||||||||||||||||||||
1441 | QElapsedTimer now; | - | ||||||||||||||||||||||||
1442 | now.start(); | - | ||||||||||||||||||||||||
1443 | uint ms = now.msecsSinceReference(); | - | ||||||||||||||||||||||||
1444 | message.append(QString::asprintf("%6d.%03d", uint(ms / 1000), uint(ms % 1000))); | - | ||||||||||||||||||||||||
1445 | } else if (timeFormat.isEmpty()) { never executed: end of block
| 0-30 | ||||||||||||||||||||||||
1446 | message.append(QDateTime::currentDateTime().toString(Qt::ISODate)); | - | ||||||||||||||||||||||||
1447 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1448 | message.append(QDateTime::currentDateTime().toString(timeFormat)); | - | ||||||||||||||||||||||||
1449 | } executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||||||||||||||||||||
1450 | #endif | - | ||||||||||||||||||||||||
1451 | } else if (token == ifCategoryTokenC) {
| 514-254182 | ||||||||||||||||||||||||
1452 | if (!context.category || (strcmp(context.category, "default") == 0))
| 3-254177 | ||||||||||||||||||||||||
1453 | skip = true; executed 254179 times by 106 tests: skip = true; Executed by:
| 254179 | ||||||||||||||||||||||||
1454 | #define HANDLE_IF_TOKEN(LEVEL) \ | - | ||||||||||||||||||||||||
1455 | } else if (token == if##LEVEL##TokenC) { \ | - | ||||||||||||||||||||||||
1456 | skip = type != Qt##LEVEL##Msg; | - | ||||||||||||||||||||||||
1457 | HANDLE_IF_TOKEN(Debug) executed 254182 times by 106 tests: end of block Executed by:
| 30-254182 | ||||||||||||||||||||||||
1458 | HANDLE_IF_TOKEN(Info) executed 30 times by 2 tests: end of block Executed by:
| 6-478 | ||||||||||||||||||||||||
1459 | HANDLE_IF_TOKEN(Warning) executed 6 times by 1 test: end of block Executed by:
| 6-444 | ||||||||||||||||||||||||
1460 | HANDLE_IF_TOKEN(Critical) executed 34 times by 2 tests: end of block Executed by:
| 14-430 | ||||||||||||||||||||||||
1461 | HANDLE_IF_TOKEN(Fatal) executed 14 times by 2 tests: end of block Executed by:
| 14-416 | ||||||||||||||||||||||||
1462 | #undef HANDLE_IF_TOKEN | - | ||||||||||||||||||||||||
1463 | } else { executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||||||||||||||||||||
1464 | message.append(QLatin1String(token)); | - | ||||||||||||||||||||||||
1465 | } executed 416 times by 3 tests: end of block Executed by:
| 416 | ||||||||||||||||||||||||
1466 | } | - | ||||||||||||||||||||||||
1467 | return message; executed 254286 times by 106 tests: return message; Executed by:
| 254286 | ||||||||||||||||||||||||
1468 | } | - | ||||||||||||||||||||||||
1469 | - | |||||||||||||||||||||||||
1470 | #if !QT_DEPRECATED_SINCE(5, 0) | - | ||||||||||||||||||||||||
1471 | // make sure they're defined to be exported | - | ||||||||||||||||||||||||
1472 | typedef void (*QtMsgHandler)(QtMsgType, const char *); | - | ||||||||||||||||||||||||
1473 | Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler); | - | ||||||||||||||||||||||||
1474 | #endif | - | ||||||||||||||||||||||||
1475 | - | |||||||||||||||||||||||||
1476 | static void qDefaultMsgHandler(QtMsgType type, const char *buf); | - | ||||||||||||||||||||||||
1477 | static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &buf); | - | ||||||||||||||||||||||||
1478 | - | |||||||||||||||||||||||||
1479 | // pointer to QtMsgHandler debug handler (without context) | - | ||||||||||||||||||||||||
1480 | static QBasicAtomicPointer<void (QtMsgType, const char*)> msgHandler = Q_BASIC_ATOMIC_INITIALIZER(qDefaultMsgHandler); | - | ||||||||||||||||||||||||
1481 | // pointer to QtMessageHandler debug handler (with context) | - | ||||||||||||||||||||||||
1482 | static QBasicAtomicPointer<void (QtMsgType, const QMessageLogContext &, const QString &)> messageHandler = Q_BASIC_ATOMIC_INITIALIZER(qDefaultMessageHandler); | - | ||||||||||||||||||||||||
1483 | - | |||||||||||||||||||||||||
1484 | #if defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
1485 | static void systemd_default_message_handler(QtMsgType type, | - | ||||||||||||||||||||||||
1486 | const QMessageLogContext &context, | - | ||||||||||||||||||||||||
1487 | const QString &message) | - | ||||||||||||||||||||||||
1488 | { | - | ||||||||||||||||||||||||
1489 | int priority = LOG_INFO; // Informational | - | ||||||||||||||||||||||||
1490 | switch (type) { | - | ||||||||||||||||||||||||
1491 | case QtDebugMsg: | - | ||||||||||||||||||||||||
1492 | priority = LOG_DEBUG; // Debug-level messages | - | ||||||||||||||||||||||||
1493 | break; | - | ||||||||||||||||||||||||
1494 | case QtInfoMsg: | - | ||||||||||||||||||||||||
1495 | priority = LOG_INFO; // Informational conditions | - | ||||||||||||||||||||||||
1496 | break; | - | ||||||||||||||||||||||||
1497 | case QtWarningMsg: | - | ||||||||||||||||||||||||
1498 | priority = LOG_WARNING; // Warning conditions | - | ||||||||||||||||||||||||
1499 | break; | - | ||||||||||||||||||||||||
1500 | case QtCriticalMsg: | - | ||||||||||||||||||||||||
1501 | priority = LOG_CRIT; // Critical conditions | - | ||||||||||||||||||||||||
1502 | break; | - | ||||||||||||||||||||||||
1503 | case QtFatalMsg: | - | ||||||||||||||||||||||||
1504 | priority = LOG_ALERT; // Action must be taken immediately | - | ||||||||||||||||||||||||
1505 | break; | - | ||||||||||||||||||||||||
1506 | } | - | ||||||||||||||||||||||||
1507 | - | |||||||||||||||||||||||||
1508 | sd_journal_send("MESSAGE=%s", message.toUtf8().constData(), | - | ||||||||||||||||||||||||
1509 | "PRIORITY=%i", priority, | - | ||||||||||||||||||||||||
1510 | "CODE_FUNC=%s", context.function ? context.function : "unknown", | - | ||||||||||||||||||||||||
1511 | "CODE_LINE=%d", context.line, | - | ||||||||||||||||||||||||
1512 | "CODE_FILE=%s", context.file ? context.file : "unknown", | - | ||||||||||||||||||||||||
1513 | "QT_CATEGORY=%s", context.category ? context.category : "unknown", | - | ||||||||||||||||||||||||
1514 | NULL); | - | ||||||||||||||||||||||||
1515 | } | - | ||||||||||||||||||||||||
1516 | #endif | - | ||||||||||||||||||||||||
1517 | - | |||||||||||||||||||||||||
1518 | #ifdef QT_USE_SYSLOG | - | ||||||||||||||||||||||||
1519 | static void syslog_default_message_handler(QtMsgType type, const char *message) | - | ||||||||||||||||||||||||
1520 | { | - | ||||||||||||||||||||||||
1521 | int priority = LOG_INFO; // Informational | - | ||||||||||||||||||||||||
1522 | switch (type) { | - | ||||||||||||||||||||||||
1523 | case QtDebugMsg: | - | ||||||||||||||||||||||||
1524 | priority = LOG_DEBUG; // Debug-level messages | - | ||||||||||||||||||||||||
1525 | break; | - | ||||||||||||||||||||||||
1526 | case QtInfoMsg: | - | ||||||||||||||||||||||||
1527 | priority = LOG_INFO; // Informational conditions | - | ||||||||||||||||||||||||
1528 | break; | - | ||||||||||||||||||||||||
1529 | case QtWarningMsg: | - | ||||||||||||||||||||||||
1530 | priority = LOG_WARNING; // Warning conditions | - | ||||||||||||||||||||||||
1531 | break; | - | ||||||||||||||||||||||||
1532 | case QtCriticalMsg: | - | ||||||||||||||||||||||||
1533 | priority = LOG_CRIT; // Critical conditions | - | ||||||||||||||||||||||||
1534 | break; | - | ||||||||||||||||||||||||
1535 | case QtFatalMsg: | - | ||||||||||||||||||||||||
1536 | priority = LOG_ALERT; // Action must be taken immediately | - | ||||||||||||||||||||||||
1537 | break; | - | ||||||||||||||||||||||||
1538 | } | - | ||||||||||||||||||||||||
1539 | - | |||||||||||||||||||||||||
1540 | syslog(priority, "%s", message); | - | ||||||||||||||||||||||||
1541 | } | - | ||||||||||||||||||||||||
1542 | #endif | - | ||||||||||||||||||||||||
1543 | - | |||||||||||||||||||||||||
1544 | #ifdef Q_OS_ANDROID | - | ||||||||||||||||||||||||
1545 | static void android_default_message_handler(QtMsgType type, | - | ||||||||||||||||||||||||
1546 | const QMessageLogContext &context, | - | ||||||||||||||||||||||||
1547 | const QString &message) | - | ||||||||||||||||||||||||
1548 | { | - | ||||||||||||||||||||||||
1549 | android_LogPriority priority = ANDROID_LOG_DEBUG; | - | ||||||||||||||||||||||||
1550 | switch (type) { | - | ||||||||||||||||||||||||
1551 | case QtDebugMsg: priority = ANDROID_LOG_DEBUG; break; | - | ||||||||||||||||||||||||
1552 | case QtInfoMsg: priority = ANDROID_LOG_INFO; break; | - | ||||||||||||||||||||||||
1553 | case QtWarningMsg: priority = ANDROID_LOG_WARN; break; | - | ||||||||||||||||||||||||
1554 | case QtCriticalMsg: priority = ANDROID_LOG_ERROR; break; | - | ||||||||||||||||||||||||
1555 | case QtFatalMsg: priority = ANDROID_LOG_FATAL; break; | - | ||||||||||||||||||||||||
1556 | }; | - | ||||||||||||||||||||||||
1557 | - | |||||||||||||||||||||||||
1558 | __android_log_print(priority, qPrintable(QCoreApplication::applicationName()), | - | ||||||||||||||||||||||||
1559 | "%s:%d (%s): %s\n", context.file, context.line, | - | ||||||||||||||||||||||||
1560 | context.function, qPrintable(message)); | - | ||||||||||||||||||||||||
1561 | } | - | ||||||||||||||||||||||||
1562 | #endif //Q_OS_ANDROID | - | ||||||||||||||||||||||||
1563 | - | |||||||||||||||||||||||||
1564 | /*! | - | ||||||||||||||||||||||||
1565 | \internal | - | ||||||||||||||||||||||||
1566 | */ | - | ||||||||||||||||||||||||
1567 | static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, | - | ||||||||||||||||||||||||
1568 | const QString &buf) | - | ||||||||||||||||||||||||
1569 | { | - | ||||||||||||||||||||||||
1570 | QString logMessage = qFormatLogMessage(type, context, buf); | - | ||||||||||||||||||||||||
1571 | - | |||||||||||||||||||||||||
1572 | // print nothing if message pattern didn't apply / was empty. | - | ||||||||||||||||||||||||
1573 | // (still print empty lines, e.g. because message itself was empty) | - | ||||||||||||||||||||||||
1574 | if (logMessage.isNull()) | - | ||||||||||||||||||||||||
1575 | return; | - | ||||||||||||||||||||||||
1576 | - | |||||||||||||||||||||||||
1577 | if (!qt_logging_to_console()) { | - | ||||||||||||||||||||||||
1578 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
1579 | logMessage.append(QLatin1Char('\n')); | - | ||||||||||||||||||||||||
1580 | OutputDebugString(reinterpret_cast<const wchar_t *>(logMessage.utf16())); | - | ||||||||||||||||||||||||
1581 | return; | - | ||||||||||||||||||||||||
1582 | #elif defined(QT_USE_SLOG2) | - | ||||||||||||||||||||||||
1583 | logMessage.append(QLatin1Char('\n')); | - | ||||||||||||||||||||||||
1584 | slog2_default_handler(type, logMessage.toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
1585 | return; | - | ||||||||||||||||||||||||
1586 | #elif defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
1587 | systemd_default_message_handler(type, context, logMessage); | - | ||||||||||||||||||||||||
1588 | return; | - | ||||||||||||||||||||||||
1589 | #elif defined(QT_USE_SYSLOG) && !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||||||||
1590 | syslog_default_message_handler(type, logMessage.toUtf8().constData()); | - | ||||||||||||||||||||||||
1591 | return; | - | ||||||||||||||||||||||||
1592 | #elif defined(Q_OS_ANDROID) | - | ||||||||||||||||||||||||
1593 | android_default_message_handler(type, context, logMessage); | - | ||||||||||||||||||||||||
1594 | return; | - | ||||||||||||||||||||||||
1595 | #endif | - | ||||||||||||||||||||||||
1596 | } | - | ||||||||||||||||||||||||
1597 | fprintf(stderr, "%s\n", logMessage.toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
1598 | fflush(stderr); | - | ||||||||||||||||||||||||
1599 | } | - | ||||||||||||||||||||||||
1600 | - | |||||||||||||||||||||||||
1601 | /*! | - | ||||||||||||||||||||||||
1602 | \internal | - | ||||||||||||||||||||||||
1603 | */ | - | ||||||||||||||||||||||||
1604 | static void qDefaultMsgHandler(QtMsgType type, const char *buf) | - | ||||||||||||||||||||||||
1605 | { | - | ||||||||||||||||||||||||
1606 | QMessageLogContext emptyContext; | - | ||||||||||||||||||||||||
1607 | qDefaultMessageHandler(type, emptyContext, QString::fromLocal8Bit(buf)); | - | ||||||||||||||||||||||||
1608 | } | - | ||||||||||||||||||||||||
1609 | - | |||||||||||||||||||||||||
1610 | #if defined(Q_COMPILER_THREAD_LOCAL) | - | ||||||||||||||||||||||||
1611 | - | |||||||||||||||||||||||||
1612 | static thread_local bool msgHandlerGrabbed = false; | - | ||||||||||||||||||||||||
1613 | - | |||||||||||||||||||||||||
1614 | static bool grabMessageHandler() | - | ||||||||||||||||||||||||
1615 | { | - | ||||||||||||||||||||||||
1616 | if (msgHandlerGrabbed) | - | ||||||||||||||||||||||||
1617 | return false; | - | ||||||||||||||||||||||||
1618 | - | |||||||||||||||||||||||||
1619 | msgHandlerGrabbed = true; | - | ||||||||||||||||||||||||
1620 | return true; | - | ||||||||||||||||||||||||
1621 | } | - | ||||||||||||||||||||||||
1622 | - | |||||||||||||||||||||||||
1623 | static void ungrabMessageHandler() | - | ||||||||||||||||||||||||
1624 | { | - | ||||||||||||||||||||||||
1625 | msgHandlerGrabbed = false; | - | ||||||||||||||||||||||||
1626 | } | - | ||||||||||||||||||||||||
1627 | - | |||||||||||||||||||||||||
1628 | #else | - | ||||||||||||||||||||||||
1629 | static bool grabMessageHandler() { return true; } | - | ||||||||||||||||||||||||
1630 | static void ungrabMessageHandler() { } | - | ||||||||||||||||||||||||
1631 | #endif // (Q_COMPILER_THREAD_LOCAL) | - | ||||||||||||||||||||||||
1632 | - | |||||||||||||||||||||||||
1633 | static void qt_message_print(QtMsgType msgType, const QMessageLogContext &context, const QString &message) | - | ||||||||||||||||||||||||
1634 | { | - | ||||||||||||||||||||||||
1635 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||
1636 | // qDebug, qWarning, ... macros do not check whether category is enabled | - | ||||||||||||||||||||||||
1637 | if (!context.category || (strcmp(context.category, "default") == 0)) { | - | ||||||||||||||||||||||||
1638 | if (QLoggingCategory *defaultCategory = QLoggingCategory::defaultCategory()) { | - | ||||||||||||||||||||||||
1639 | if (!defaultCategory->isEnabled(msgType)) | - | ||||||||||||||||||||||||
1640 | return; | - | ||||||||||||||||||||||||
1641 | } | - | ||||||||||||||||||||||||
1642 | } | - | ||||||||||||||||||||||||
1643 | #endif | - | ||||||||||||||||||||||||
1644 | - | |||||||||||||||||||||||||
1645 | // prevent recursion in case the message handler generates messages | - | ||||||||||||||||||||||||
1646 | // itself, e.g. by using Qt API | - | ||||||||||||||||||||||||
1647 | if (grabMessageHandler()) { | - | ||||||||||||||||||||||||
1648 | // prefer new message handler over the old one | - | ||||||||||||||||||||||||
1649 | if (msgHandler.load() == qDefaultMsgHandler | - | ||||||||||||||||||||||||
1650 | || messageHandler.load() != qDefaultMessageHandler) { | - | ||||||||||||||||||||||||
1651 | (*messageHandler.load())(msgType, context, message); | - | ||||||||||||||||||||||||
1652 | } else { | - | ||||||||||||||||||||||||
1653 | (*msgHandler.load())(msgType, message.toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
1654 | } | - | ||||||||||||||||||||||||
1655 | ungrabMessageHandler(); | - | ||||||||||||||||||||||||
1656 | } else { | - | ||||||||||||||||||||||||
1657 | fprintf(stderr, "%s\n", message.toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
1658 | } | - | ||||||||||||||||||||||||
1659 | } | - | ||||||||||||||||||||||||
1660 | - | |||||||||||||||||||||||||
1661 | static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, const QString &message) | - | ||||||||||||||||||||||||
1662 | { | - | ||||||||||||||||||||||||
1663 | #if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) | - | ||||||||||||||||||||||||
1664 | wchar_t contextFileL[256]; | - | ||||||||||||||||||||||||
1665 | // we probably should let the compiler do this for us, by declaring QMessageLogContext::file to | - | ||||||||||||||||||||||||
1666 | // be const wchar_t * in the first place, but the #ifdefery above is very complex and we | - | ||||||||||||||||||||||||
1667 | // wouldn't be able to change it later on... | - | ||||||||||||||||||||||||
1668 | convert_to_wchar_t_elided(contextFileL, sizeof contextFileL / sizeof *contextFileL, | - | ||||||||||||||||||||||||
1669 | context.file); | - | ||||||||||||||||||||||||
1670 | // get the current report mode | - | ||||||||||||||||||||||||
1671 | int reportMode = _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_WNDW); | - | ||||||||||||||||||||||||
1672 | _CrtSetReportMode(_CRT_ERROR, reportMode); | - | ||||||||||||||||||||||||
1673 | - | |||||||||||||||||||||||||
1674 | int ret = _CrtDbgReportW(_CRT_ERROR, contextFileL, context.line, _CRT_WIDE(QT_VERSION_STR), | - | ||||||||||||||||||||||||
1675 | reinterpret_cast<const wchar_t *>(message.utf16())); | - | ||||||||||||||||||||||||
1676 | if ((ret == 0) && (reportMode & _CRTDBG_MODE_WNDW)) | - | ||||||||||||||||||||||||
1677 | return; // ignore | - | ||||||||||||||||||||||||
1678 | else if (ret == 1) | - | ||||||||||||||||||||||||
1679 | _CrtDbgBreak(); | - | ||||||||||||||||||||||||
1680 | #else | - | ||||||||||||||||||||||||
1681 | Q_UNUSED(context); | - | ||||||||||||||||||||||||
1682 | Q_UNUSED(message); | - | ||||||||||||||||||||||||
1683 | #endif | - | ||||||||||||||||||||||||
1684 | - | |||||||||||||||||||||||||
1685 | #if (defined(Q_OS_UNIX) || defined(Q_CC_MINGW)) | - | ||||||||||||||||||||||||
1686 | abort(); // trap; generates core dump | - | ||||||||||||||||||||||||
1687 | #else | - | ||||||||||||||||||||||||
1688 | exit(1); // goodbye cruel world | - | ||||||||||||||||||||||||
1689 | #endif | - | ||||||||||||||||||||||||
1690 | } | - | ||||||||||||||||||||||||
1691 | - | |||||||||||||||||||||||||
1692 | - | |||||||||||||||||||||||||
1693 | /*! | - | ||||||||||||||||||||||||
1694 | \internal | - | ||||||||||||||||||||||||
1695 | */ | - | ||||||||||||||||||||||||
1696 | void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const QString &message) | - | ||||||||||||||||||||||||
1697 | { | - | ||||||||||||||||||||||||
1698 | qt_message_print(msgType, context, message); | - | ||||||||||||||||||||||||
1699 | if (isFatal(msgType)) | - | ||||||||||||||||||||||||
1700 | qt_message_fatal(msgType, context, message); | - | ||||||||||||||||||||||||
1701 | } | - | ||||||||||||||||||||||||
1702 | - | |||||||||||||||||||||||||
1703 | void qErrnoWarning(const char *msg, ...) | - | ||||||||||||||||||||||||
1704 | { | - | ||||||||||||||||||||||||
1705 | // qt_error_string() will allocate anyway, so we don't have | - | ||||||||||||||||||||||||
1706 | // to be careful here (like we do in plain qWarning()) | - | ||||||||||||||||||||||||
1707 | va_list ap; | - | ||||||||||||||||||||||||
1708 | va_start(ap, msg); | - | ||||||||||||||||||||||||
1709 | QString buf = QString::vasprintf(msg, ap); | - | ||||||||||||||||||||||||
1710 | va_end(ap); | - | ||||||||||||||||||||||||
1711 | - | |||||||||||||||||||||||||
1712 | buf += QLatin1String(" (") + qt_error_string(-1) + QLatin1Char(')'); | - | ||||||||||||||||||||||||
1713 | QMessageLogContext context; | - | ||||||||||||||||||||||||
1714 | qt_message_output(QtCriticalMsg, context, buf); | - | ||||||||||||||||||||||||
1715 | } | - | ||||||||||||||||||||||||
1716 | - | |||||||||||||||||||||||||
1717 | void qErrnoWarning(int code, const char *msg, ...) | - | ||||||||||||||||||||||||
1718 | { | - | ||||||||||||||||||||||||
1719 | // qt_error_string() will allocate anyway, so we don't have | - | ||||||||||||||||||||||||
1720 | // to be careful here (like we do in plain qWarning()) | - | ||||||||||||||||||||||||
1721 | va_list ap; | - | ||||||||||||||||||||||||
1722 | va_start(ap, msg); | - | ||||||||||||||||||||||||
1723 | QString buf = QString::vasprintf(msg, ap); | - | ||||||||||||||||||||||||
1724 | va_end(ap); | - | ||||||||||||||||||||||||
1725 | - | |||||||||||||||||||||||||
1726 | buf += QLatin1String(" (") + qt_error_string(code) + QLatin1Char(')'); | - | ||||||||||||||||||||||||
1727 | QMessageLogContext context; | - | ||||||||||||||||||||||||
1728 | qt_message_output(QtCriticalMsg, context, buf); | - | ||||||||||||||||||||||||
1729 | } | - | ||||||||||||||||||||||||
1730 | - | |||||||||||||||||||||||||
1731 | /*! | - | ||||||||||||||||||||||||
1732 | \typedef QtMsgHandler | - | ||||||||||||||||||||||||
1733 | \relates <QtGlobal> | - | ||||||||||||||||||||||||
1734 | \deprecated | - | ||||||||||||||||||||||||
1735 | - | |||||||||||||||||||||||||
1736 | This is a typedef for a pointer to a function with the following | - | ||||||||||||||||||||||||
1737 | signature: | - | ||||||||||||||||||||||||
1738 | - | |||||||||||||||||||||||||
1739 | \snippet code/src_corelib_global_qglobal.cpp 7 | - | ||||||||||||||||||||||||
1740 | - | |||||||||||||||||||||||||
1741 | This typedef is deprecated, you should use QtMessageHandler instead. | - | ||||||||||||||||||||||||
1742 | \sa QtMsgType, QtMessageHandler, qInstallMsgHandler(), qInstallMessageHandler() | - | ||||||||||||||||||||||||
1743 | */ | - | ||||||||||||||||||||||||
1744 | - | |||||||||||||||||||||||||
1745 | /*! | - | ||||||||||||||||||||||||
1746 | \typedef QtMessageHandler | - | ||||||||||||||||||||||||
1747 | \relates <QtGlobal> | - | ||||||||||||||||||||||||
1748 | \since 5.0 | - | ||||||||||||||||||||||||
1749 | - | |||||||||||||||||||||||||
1750 | This is a typedef for a pointer to a function with the following | - | ||||||||||||||||||||||||
1751 | signature: | - | ||||||||||||||||||||||||
1752 | - | |||||||||||||||||||||||||
1753 | \snippet code/src_corelib_global_qglobal.cpp 49 | - | ||||||||||||||||||||||||
1754 | - | |||||||||||||||||||||||||
1755 | \sa QtMsgType, qInstallMessageHandler() | - | ||||||||||||||||||||||||
1756 | */ | - | ||||||||||||||||||||||||
1757 | - | |||||||||||||||||||||||||
1758 | /*! | - | ||||||||||||||||||||||||
1759 | \fn QtMessageHandler qInstallMessageHandler(QtMessageHandler handler) | - | ||||||||||||||||||||||||
1760 | \relates <QtGlobal> | - | ||||||||||||||||||||||||
1761 | \since 5.0 | - | ||||||||||||||||||||||||
1762 | - | |||||||||||||||||||||||||
1763 | Installs a Qt message \a handler which has been defined | - | ||||||||||||||||||||||||
1764 | previously. Returns a pointer to the previous message handler. | - | ||||||||||||||||||||||||
1765 | - | |||||||||||||||||||||||||
1766 | The message handler is a function that prints out debug messages, | - | ||||||||||||||||||||||||
1767 | warnings, critical and fatal error messages. The Qt library (debug | - | ||||||||||||||||||||||||
1768 | mode) contains hundreds of warning messages that are printed | - | ||||||||||||||||||||||||
1769 | when internal errors (usually invalid function arguments) | - | ||||||||||||||||||||||||
1770 | occur. Qt built in release mode also contains such warnings unless | - | ||||||||||||||||||||||||
1771 | QT_NO_WARNING_OUTPUT and/or QT_NO_DEBUG_OUTPUT have been set during | - | ||||||||||||||||||||||||
1772 | compilation. If you implement your own message handler, you get total | - | ||||||||||||||||||||||||
1773 | control of these messages. | - | ||||||||||||||||||||||||
1774 | - | |||||||||||||||||||||||||
1775 | The default message handler prints the message to the standard | - | ||||||||||||||||||||||||
1776 | output under X11 or to the debugger under Windows. If it is a | - | ||||||||||||||||||||||||
1777 | fatal message, the application aborts immediately. | - | ||||||||||||||||||||||||
1778 | - | |||||||||||||||||||||||||
1779 | Only one message handler can be defined, since this is usually | - | ||||||||||||||||||||||||
1780 | done on an application-wide basis to control debug output. | - | ||||||||||||||||||||||||
1781 | - | |||||||||||||||||||||||||
1782 | To restore the message handler, call \c qInstallMessageHandler(0). | - | ||||||||||||||||||||||||
1783 | - | |||||||||||||||||||||||||
1784 | Example: | - | ||||||||||||||||||||||||
1785 | - | |||||||||||||||||||||||||
1786 | \snippet code/src_corelib_global_qglobal.cpp 23 | - | ||||||||||||||||||||||||
1787 | - | |||||||||||||||||||||||||
1788 | \sa QtMessageHandler, QtMsgType, qDebug(), qInfo(), qWarning(), qCritical(), qFatal(), | - | ||||||||||||||||||||||||
1789 | {Debugging Techniques} | - | ||||||||||||||||||||||||
1790 | */ | - | ||||||||||||||||||||||||
1791 | - | |||||||||||||||||||||||||
1792 | /*! | - | ||||||||||||||||||||||||
1793 | \fn QtMsgHandler qInstallMsgHandler(QtMsgHandler handler) | - | ||||||||||||||||||||||||
1794 | \relates <QtGlobal> | - | ||||||||||||||||||||||||
1795 | \deprecated | - | ||||||||||||||||||||||||
1796 | - | |||||||||||||||||||||||||
1797 | Installs a Qt message \a handler which has been defined | - | ||||||||||||||||||||||||
1798 | previously. This method is deprecated, use qInstallMessageHandler | - | ||||||||||||||||||||||||
1799 | instead. | - | ||||||||||||||||||||||||
1800 | \sa QtMsgHandler, qInstallMessageHandler() | - | ||||||||||||||||||||||||
1801 | */ | - | ||||||||||||||||||||||||
1802 | /*! | - | ||||||||||||||||||||||||
1803 | \fn void qSetMessagePattern(const QString &pattern) | - | ||||||||||||||||||||||||
1804 | \relates <QtGlobal> | - | ||||||||||||||||||||||||
1805 | \since 5.0 | - | ||||||||||||||||||||||||
1806 | - | |||||||||||||||||||||||||
1807 | \brief Changes the output of the default message handler. | - | ||||||||||||||||||||||||
1808 | - | |||||||||||||||||||||||||
1809 | Allows to tweak the output of qDebug(), qInfo(), qWarning(), qCritical(), | - | ||||||||||||||||||||||||
1810 | and qFatal(). The category logging output of qCDebug(), qCInfo(), | - | ||||||||||||||||||||||||
1811 | qCWarning(), and qCCritical() is formatted, too. | - | ||||||||||||||||||||||||
1812 | - | |||||||||||||||||||||||||
1813 | Following placeholders are supported: | - | ||||||||||||||||||||||||
1814 | - | |||||||||||||||||||||||||
1815 | \table | - | ||||||||||||||||||||||||
1816 | \header \li Placeholder \li Description | - | ||||||||||||||||||||||||
1817 | \row \li \c %{appname} \li QCoreApplication::applicationName() | - | ||||||||||||||||||||||||
1818 | \row \li \c %{category} \li Logging category | - | ||||||||||||||||||||||||
1819 | \row \li \c %{file} \li Path to source file | - | ||||||||||||||||||||||||
1820 | \row \li \c %{function} \li Function | - | ||||||||||||||||||||||||
1821 | \row \li \c %{line} \li Line in source file | - | ||||||||||||||||||||||||
1822 | \row \li \c %{message} \li The actual message | - | ||||||||||||||||||||||||
1823 | \row \li \c %{pid} \li QCoreApplication::applicationPid() | - | ||||||||||||||||||||||||
1824 | \row \li \c %{threadid} \li The system-wide ID of current thread (if it can be obtained) | - | ||||||||||||||||||||||||
1825 | \row \li \c %{qthreadptr} \li A pointer to the current QThread (result of QThread::currentThread()) | - | ||||||||||||||||||||||||
1826 | \row \li \c %{type} \li "debug", "warning", "critical" or "fatal" | - | ||||||||||||||||||||||||
1827 | \row \li \c %{time process} \li time of the message, in seconds since the process started (the token "process" is literal) | - | ||||||||||||||||||||||||
1828 | \row \li \c %{time boot} \li the time of the message, in seconds since the system boot if that | - | ||||||||||||||||||||||||
1829 | can be determined (the token "boot" is literal). If the time since boot could not be obtained, | - | ||||||||||||||||||||||||
1830 | the output is indeterminate (see QElapsedTimer::msecsSinceReference()). | - | ||||||||||||||||||||||||
1831 | \row \li \c %{time [format]} \li system time when the message occurred, formatted by | - | ||||||||||||||||||||||||
1832 | passing the \c format to \l QDateTime::toString(). If the format is | - | ||||||||||||||||||||||||
1833 | not specified, the format of Qt::ISODate is used. | - | ||||||||||||||||||||||||
1834 | \row \li \c{%{backtrace [depth=N] [separator="..."]}} \li A backtrace with the number of frames | - | ||||||||||||||||||||||||
1835 | specified by the optional \c depth parameter (defaults to 5), and separated by the optional | - | ||||||||||||||||||||||||
1836 | \c separator parameter (defaults to "|"). | - | ||||||||||||||||||||||||
1837 | This expansion is available only on some platforms (currently only platfoms using glibc). | - | ||||||||||||||||||||||||
1838 | Names are only known for exported functions. If you want to see the name of every function | - | ||||||||||||||||||||||||
1839 | in your application, use \c{QMAKE_LFLAGS += -rdynamic}. | - | ||||||||||||||||||||||||
1840 | When reading backtraces, take into account that frames might be missing due to inlining or | - | ||||||||||||||||||||||||
1841 | tail call optimization. | - | ||||||||||||||||||||||||
1842 | \endtable | - | ||||||||||||||||||||||||
1843 | - | |||||||||||||||||||||||||
1844 | You can also use conditionals on the type of the message using \c %{if-debug}, \c %{if-info} | - | ||||||||||||||||||||||||
1845 | \c %{if-warning}, \c %{if-critical} or \c %{if-fatal} followed by an \c %{endif}. | - | ||||||||||||||||||||||||
1846 | What is inside the \c %{if-*} and \c %{endif} will only be printed if the type matches. | - | ||||||||||||||||||||||||
1847 | - | |||||||||||||||||||||||||
1848 | Finally, text inside \c %{if-category} ... \c %{endif} is only printed if the category | - | ||||||||||||||||||||||||
1849 | is not the default one. | - | ||||||||||||||||||||||||
1850 | - | |||||||||||||||||||||||||
1851 | Example: | - | ||||||||||||||||||||||||
1852 | \code | - | ||||||||||||||||||||||||
1853 | QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}" | - | ||||||||||||||||||||||||
1854 | \endcode | - | ||||||||||||||||||||||||
1855 | - | |||||||||||||||||||||||||
1856 | The default \a pattern is "%{if-category}%{category}: %{endif}%{message}". | - | ||||||||||||||||||||||||
1857 | - | |||||||||||||||||||||||||
1858 | The \a pattern can also be changed at runtime by setting the QT_MESSAGE_PATTERN | - | ||||||||||||||||||||||||
1859 | environment variable; if both \l qSetMessagePattern() is called and QT_MESSAGE_PATTERN is | - | ||||||||||||||||||||||||
1860 | set, the environment variable takes precedence. | - | ||||||||||||||||||||||||
1861 | - | |||||||||||||||||||||||||
1862 | Custom message handlers can use qFormatLogMessage() to take \a pattern into account. | - | ||||||||||||||||||||||||
1863 | - | |||||||||||||||||||||||||
1864 | \sa qInstallMessageHandler(), {Debugging Techniques}, {QLoggingCategory} | - | ||||||||||||||||||||||||
1865 | */ | - | ||||||||||||||||||||||||
1866 | - | |||||||||||||||||||||||||
1867 | QtMessageHandler qInstallMessageHandler(QtMessageHandler h) | - | ||||||||||||||||||||||||
1868 | { | - | ||||||||||||||||||||||||
1869 | if (!h) | - | ||||||||||||||||||||||||
1870 | h = qDefaultMessageHandler; | - | ||||||||||||||||||||||||
1871 | //set 'h' and return old message handler | - | ||||||||||||||||||||||||
1872 | return messageHandler.fetchAndStoreRelaxed(h); | - | ||||||||||||||||||||||||
1873 | } | - | ||||||||||||||||||||||||
1874 | - | |||||||||||||||||||||||||
1875 | QtMsgHandler qInstallMsgHandler(QtMsgHandler h) | - | ||||||||||||||||||||||||
1876 | { | - | ||||||||||||||||||||||||
1877 | if (!h) | - | ||||||||||||||||||||||||
1878 | h = qDefaultMsgHandler; | - | ||||||||||||||||||||||||
1879 | //set 'h' and return old message handler | - | ||||||||||||||||||||||||
1880 | return msgHandler.fetchAndStoreRelaxed(h); | - | ||||||||||||||||||||||||
1881 | } | - | ||||||||||||||||||||||||
1882 | - | |||||||||||||||||||||||||
1883 | void qSetMessagePattern(const QString &pattern) | - | ||||||||||||||||||||||||
1884 | { | - | ||||||||||||||||||||||||
1885 | QMutexLocker lock(&QMessagePattern::mutex); | - | ||||||||||||||||||||||||
1886 | - | |||||||||||||||||||||||||
1887 | if (!qMessagePattern()->fromEnvironment) | - | ||||||||||||||||||||||||
1888 | qMessagePattern()->setPattern(pattern); | - | ||||||||||||||||||||||||
1889 | } | - | ||||||||||||||||||||||||
1890 | - | |||||||||||||||||||||||||
1891 | - | |||||||||||||||||||||||||
1892 | /*! | - | ||||||||||||||||||||||||
1893 | Copies context information from \a logContext into this QMessageLogContext | - | ||||||||||||||||||||||||
1894 | \internal | - | ||||||||||||||||||||||||
1895 | */ | - | ||||||||||||||||||||||||
1896 | void QMessageLogContext::copy(const QMessageLogContext &logContext) | - | ||||||||||||||||||||||||
1897 | { | - | ||||||||||||||||||||||||
1898 | this->category = logContext.category; | - | ||||||||||||||||||||||||
1899 | this->file = logContext.file; | - | ||||||||||||||||||||||||
1900 | this->line = logContext.line; | - | ||||||||||||||||||||||||
1901 | this->function = logContext.function; | - | ||||||||||||||||||||||||
1902 | } | - | ||||||||||||||||||||||||
1903 | - | |||||||||||||||||||||||||
1904 | /*! | - | ||||||||||||||||||||||||
1905 | \fn QMessageLogger::QMessageLogger() | - | ||||||||||||||||||||||||
1906 | - | |||||||||||||||||||||||||
1907 | Constructs a default QMessageLogger. See the other constructors to specify | - | ||||||||||||||||||||||||
1908 | context information. | - | ||||||||||||||||||||||||
1909 | */ | - | ||||||||||||||||||||||||
1910 | - | |||||||||||||||||||||||||
1911 | /*! | - | ||||||||||||||||||||||||
1912 | \fn QMessageLogger::QMessageLogger(const char *file, int line, const char *function) | - | ||||||||||||||||||||||||
1913 | - | |||||||||||||||||||||||||
1914 | Constructs a QMessageLogger to record log messages for \a file at \a line | - | ||||||||||||||||||||||||
1915 | in \a function. The is equivalent to QMessageLogger(file, line, function, "default") | - | ||||||||||||||||||||||||
1916 | */ | - | ||||||||||||||||||||||||
1917 | /*! | - | ||||||||||||||||||||||||
1918 | \fn QMessageLogger::QMessageLogger(const char *file, int line, const char *function, const char *category) | - | ||||||||||||||||||||||||
1919 | - | |||||||||||||||||||||||||
1920 | Constructs a QMessageLogger to record \a category messages for \a file at \a line | - | ||||||||||||||||||||||||
1921 | in \a function. | - | ||||||||||||||||||||||||
1922 | */ | - | ||||||||||||||||||||||||
1923 | - | |||||||||||||||||||||||||
1924 | /*! | - | ||||||||||||||||||||||||
1925 | \fn void QMessageLogger::noDebug(const char *, ...) const | - | ||||||||||||||||||||||||
1926 | \internal | - | ||||||||||||||||||||||||
1927 | - | |||||||||||||||||||||||||
1928 | Ignores logging output | - | ||||||||||||||||||||||||
1929 | - | |||||||||||||||||||||||||
1930 | \sa QNoDebug, qDebug() | - | ||||||||||||||||||||||||
1931 | */ | - | ||||||||||||||||||||||||
1932 | - | |||||||||||||||||||||||||
1933 | /*! | - | ||||||||||||||||||||||||
1934 | \fn QMessageLogContext::QMessageLogContext() | - | ||||||||||||||||||||||||
1935 | \internal | - | ||||||||||||||||||||||||
1936 | - | |||||||||||||||||||||||||
1937 | Constructs a QMessageLogContext | - | ||||||||||||||||||||||||
1938 | */ | - | ||||||||||||||||||||||||
1939 | - | |||||||||||||||||||||||||
1940 | /*! | - | ||||||||||||||||||||||||
1941 | \fn QMessageLogContext::QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) | - | ||||||||||||||||||||||||
1942 | \internal | - | ||||||||||||||||||||||||
1943 | - | |||||||||||||||||||||||||
1944 | Constructs a QMessageLogContext with for file \a fileName at line | - | ||||||||||||||||||||||||
1945 | \a lineNumber, in function \a functionName, and category \a categoryName. | - | ||||||||||||||||||||||||
1946 | */ | - | ||||||||||||||||||||||||
1947 | - | |||||||||||||||||||||||||
1948 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |