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