summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlogging.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QLogging: fix narrowing conversion assertAhmad Samir2025-10-071-1/+1
| | | | | | | | | Amends a213dca680827336cb63de743be3f019c4521808. Pointed out by Eddy in code review. Pick-to: 6.10 6.8 6.5 Change-Id: I061f9892384fe62650dfec23842686d1ba53130a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* corelib: fix clang narrowing conversion warnings -Wshorten-64-to-32Ahmad Samir2025-10-061-1/+2
| | | | | | | | | | | | | | qlogging.cpp: ::backtrace() takes an int. QLoggingSettingsParser: fgets() takes an int. QFileSystemEntry: filePath() would never exceed PATH_MAX on Unix; and on windows even with the extended long path option it should fit in an int: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation Pick-to: 6.10 6.8 6.5 Change-Id: I288f4adc71740e077ed0c11de4e38f6fddc00455 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Improve documentation of qDebug and friendsKai Köhne2025-07-291-83/+55
| | | | | | | | | | | | | | | | | | | | Document the QDebug stream operator variants separately, as part of QDebug (where they belong). Reorder the remaining documentation for better readability: Talk about the arguments and show an example first. Mention common placeholders like %s and %i for easier access. Give the details about the exact sink behavior later. Do not mention the default message logger behavior, as that is better documented centreally. Also, call the first argument of the printf() style debug format, to make it more obvious that it can contain placeholders and format options. Pick-to: 6.9 6.10 Change-Id: I370f490a524123c635d6c84feda385dad5174dcc Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
* Add snippets to the build system and fix related issuesOleksii Zbykovskyi2025-07-241-1/+1
| | | | | | | | | | | | Created CMakeLists.txt file with all compilable snippets by now, and added it to the build system. Also fixed some previous files to make them build correctly. And fixed some documentation related to the snippets change. Task-number: QTBUG-137566 Change-Id: Ibf4321dd243bdf774c508bc1e43f9019a9074c30 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Add more snippets sources from corelib to the build systemOleksii Zbykovskyi2025-06-261-2/+2
| | | | | | | | | | | | | | Trying to compile snippets and fixing some bugs with them. Added some files and targets to CMakeList.txt. Added SOURCES of files that triggers Widgets in CMakeList.txt. Handled "no widgets" and "no qml" cases for snippets compiling. Relocated the necessary header file for qtcast. All others are just small fixes. Update: fixed path to the qlogging snippet in docs Task-number: QTBUG-137566 Change-Id: I6c6068790bf24ca88072cf8ca5c33b1401551452 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QLogging: fix potential UB in QBasicAtomic initializationMarc Mutz2025-06-091-2/+2
| | | | | | | | | | | | | | | | | | | Until C++17 (inclusive), a default-constructed std::atomic object can, officially, only be initialized with a call to std::atomic_init, for which QBasicAtomic doesn't have API. It is even unclear whether zero-initialization of static and thread-local objects will cause the object to be initialized. But initialization with = {} is definitely fishy, because that, by definition, invokes the problematic default constructor. So make the initialization explict with Q_BASIC_ATOMIC_INITIALIZER(0) instead. Amends 4a154170773199f5b3376496c7b1a1c4530744e9. Task-number: QTBUG-137465 Pick-to: 6.10 Change-Id: I177e05c09e20e0830af7bf1ccb650afc860ab9d5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLogging: use std::unique_ptr instead of QScopedPointerAhmad Samir2025-06-041-5/+8
| | | | | | Task-number: QTBUG-132213 Change-Id: I6c5e72108e4ed79e645b8dbd9b2103e13e4849d0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLogging: fix build: narrowing conversion from qsizetype to size_tThiago Macieira2025-05-261-1/+1
| | | | | | | | | | | Amends a6070847f075296458e1afef0210f9c89aca4b2a. error: narrowing conversion of ‘(& ba)->QByteArray::size()’ from ‘qsizetype’ {aka ‘long long int’} to ‘size_t’ {aka ‘long unsigned int’} [-Werror=narrowing] Task-number: QTBUG-120047 Task-number: QTBUG-120048 Change-Id: I1fe8c5d7318c398e4ef3fffd17e06f0eeccdd791 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* qlogging: Journal: Log thread id, suppress empty fieldsKai Köhne2025-05-191-7/+33
| | | | | | | | | | | | | | | | | | | | | | | | The TID field can be used to differentiate the threads of a process where the message originates from. This allows to create a timeline of events when identical messages are created from multiple threads, or filter out messages from "uninteresting" threads in post-processing. The file/line/func fields are typically empty for non-debug builds, so storing these in the journal with dummy values is a waste of CPU time and storage. Use sd_journal_sendv instead of sd_journal_send, as that allows to vary the number of sent fields, and skip the ones without actual information. It is also slightly more performant, as it avoids the var-arg handling, sprintf parsing and formatting etc. done by sd_journal_send. [ChangeLog][QtCore][Logging] Qt now logs the thread id (TID) in journal, allowing separation of identical messages from multiple threads. Fixes: QTBUG-120047 Fixes: QTBUG-120048 Change-Id: Iccf3fe708dc4b896161693e13fb9012686bd1871 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* qlogging: replace heap buffer with stack in win_outputDebugString_helperAurélien Brooke2025-05-061-2/+1
| | | | | | | | | | The stack should have room for the 64KB. We don't use std::array to avoid unecessary zero-initialization. Amends a049325cc708b483ed1aadc6589419f4d74b19f3. Change-Id: I0e2ce0a74914010e259ae832995823d382c9276c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLoggingCategory: make defaultCategory() truly a global staticThiago Macieira2025-03-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | We don't need two independent Q_GLOBAL_STATIC variables: one for the default category and the other for the logging registry. We can simply save one in the other. However, we can do better than even that. QLoggingCategory currently doesn't hold any allocated resources: the const char *name points to a static string and the void *d is always null. That means the constructor and destructor only serve to register and unregister the category with QLoggingRegistry, so we transfer that responsibility to QLoggingRegistry itself (the un-registering is implicit in the registry's own destruction). The benefit of this is that the default QLoggingCategory can never be found in a destroyed state, however late user code may be running after ::exit() was called. We have had a number of these issues of De-Initialization Order Fiasco, especially since the changes to QThreadData destruction timing. Pick-to: 6.9 Change-Id: I2b6ea597ac257837669afffde2684c7b44a42e92 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QMessageLogger: store the QT_FATAL_xxx state plus one in the atomicsThiago Macieira2025-03-191-7/+8
| | | | | | | | | Just so they're constant-initialized to zero and thus don't occupy disk space in QtCore. Change-Id: I2f876ef66b5f789c7642fffdfe073dbd65ea7a6d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QMessageLogger: initialize QT_FATAL_xxx cooperatively between threadsThiago Macieira2025-03-191-14/+38
| | | | | | | | | | | | The use of function-local static implied there was a guard variable to perform a thread-safe initialization (a critical section). We don't need that: we can just use a plain QBasicAtomicInt and cooperatively initialize, in parallel. This way, the QMessageLogger code does not need to check the status of the guard variable before every access to the atomic, which would be an atomic access before the atomic access. Change-Id: Iedfbe8e28ca5168dea43fffddf205d122c97f71c Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QMessageLogger: reject negative values for QT_FATAL_xxxThiago Macieira2025-03-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Amends ceb859bf036dfdd1c54eec403006eac62a0d09b8 We'd accept negative values and keep counting downwards, reaching 0 again only after a full underflow[*]. Effectively, this meant that a negative value was the same as zero, so this makes the behavior explicit. The commit introducing checked_var_value() said in its changelog: For compatibility reasons with previous versions, if the variable is set to any non-empty and non-numeric value different from 0, Qt will understand as "stop on first warning". Negative values are not "non-empty and non-numeric", so this commit chooses to make the current behavior explicit. [*] atomic under- and overflows are defined behavior, but only if the atomic operation is the one producing it. The current code is doing the subtraction by itself in the call to testAndSetRelaxed(), so underflows are still UB. If/when this is replaced by atomicMutate, that might change (and note to self when implementing that!). Pick-to: 6.9 6.8 Change-Id: I594ed31f1cc7fc04ea98c6e86bdcaa3a4aa59114 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QMessageLogger: Make sure we don't count to 0 QT_FATAL_xxxThiago Macieira2025-03-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Amends commit b933a5668cc5647d26378f8a9a52901d0497585d ("Make sure we don't count down past 0 QT_FATAL_CRITICALS"), which introduced the CAS. Apparently it was a design decision then that only one thread would call qAbort(), while the others would happily continue. For example, for the common case of QT_FATAL_WARNINGS=1: // T1 T2 v = n.loadRelaxed() // v = 1 v != 0 // true n.testAndSet(v, v - 1, v) // n = 0 v = n.loadRelaxed() // v = 0 v != 0 // false return v == 1; // false This commit changes that design, for two reasons. First, a semantic one: if one thread has detected a fatal condition, it must be equally fatal for all threads. Second, we must accept a meaningful time between the detected condition and the call to qAbort() and thus the time until its effects take. In the worst case scenario, T1 could get suspended indefinitely, at which point T2 having concluded that warnings weren't fatal will happily execute forever. [This could happen *because* of having called abort(), and though that's a SW bug elsewhere, we should not let our other warnings and criticals continue.] The fix is simple: we never decrement from 1. That way, if multiple threads start their verification at the same time, they will all see the value 1 and will all abort. The abort() standard library function is thread-safe, as our replacements for it. Pick-to: 6.5 6.8 6.9 Change-Id: I03fbcbac26bd1f34d631fffd43bb9c27d51783d0 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QMessagePattern: add the %{threadname} placeholderAurélien Brooke2025-03-101-0/+57
| | | | | | | | | | The thread name is often more meaningful than a number or pointer. [ChangeLog][QtCore][Logging framework] QMessagePattern / QT_MESSAGE_PATTERN now support the %{threadname} placeholder. Change-Id: I7ad8821c8b887e428023144d6e93e20c53bf757e Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMessageLogger: merge the isFatal() call into qt_message_fatal()Thiago Macieira2025-02-251-11/+7
| | | | | | | | | Making it qt_maybe_message_fatal(). Thus we're less likely to forget to do the right thing. Change-Id: Ie3c344d9f64527fc755ffffdd3c97cf8fa3fcc90 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* qlogging.cpp: clean up of QT_BOOTSTRAPPEDThiago Macieira2025-01-221-45/+8
| | | | | | | | | | Amends commit df2e07549e6edd1d271cce1d86cadd4a33dfd8fc which removed this file from the bootstrap build. Drive-by remove pre-thread_local content, which isn't needed in 2025. Change-Id: I406c748a5f0aedb5a846fffde5a2f5eb5f875f14 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QMessageLogger: simplify the backtrace codeThiago Macieira2025-01-211-3/+1
| | | | | | | | By moving one of the #if, we can remove the other. Change-Id: I167cf466ef965758e5e8fffd94f8f8169599e3c6 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* qlogging.cpp: sort the headers and move qt_windows.h to the bottomThiago Macieira2025-01-201-18/+18
| | | | | | | Standard practice. Change-Id: If8d08785be6073236e92fffd0acea703f5a7f49d Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* qlogging.cpp: move the qt_gettid() function to a headerThiago Macieira2025-01-201-38/+1
| | | | | | | Just for code organization. Change-Id: Ifa5da67b98f07f669e4ffffd1a0fc10b4087b6b2 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QMessagePattern: merge and improve %{time}-printing codeThiago Macieira2025-01-161-6/+10
| | | | | | | | | | | | | All modern compilers implement divisions and modulus via multiplications and shift, so the codegen is practically the same (three multiplications in total). But the new code allows more than 136 years of uptime (49710 days). Drive-by fix indentation in nearby line. Pick-to: 6.9 Change-Id: Iea806bd7dfac1f852c66fffd41c2ac6660e7cc65 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QMessagePattern: replace Q{Elapsed,Deadline}Timer with std::chronoThiago Macieira2025-01-161-8/+6
| | | | | | | | | | There's nothing wrong with those two, but we don't need the middle men to the monotonic clock. This also reduces the sizeof QMessagePattern by one quint64 (QElapsedTimer is 16 bytes in Qt 6). Pick-to: 6.9 Change-Id: I0eb171f03ee8f3a7148bfffd5534a7f3daba3a01 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QMessagePattern: add Q_ASSERT to setDefaultPattern() and improve codegenThiago Macieira2025-01-161-3/+9
| | | | | | | | | | | | | | Amends commit e04f109456bbcb184963b8ed71944b958b35c201. This function does not free the pointers stored in literals, so add a couple of assertions to indicate that it's only safe to call from the constructor. And that being the case, we can update the tokens unique_ptr in two steps, which makes the compiler not attempt to call delete[] on the previous pointer. Pick-to: 6.9 Change-Id: Ibe76a7df795e9c6d6191fffdf45e3b3ef6f0f344 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* qErrnoWarning: disable when QT_NO_WARNING_OUTPUT is setThiago Macieira2025-01-071-13/+0
| | | | | Change-Id: Ife98ce915b4bd3edd017fffd18c8bb775381e6f4 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QMessagePattern: "precompile" the default patternThiago Macieira2025-01-071-7/+18
| | | | | | | | | | | So we don't have to parse it on first use if it isn't set. This should be a small performance gain for everyone who uses the default, which is usually the majority of people. Pick-to: 6.9 Change-Id: I10c471715457dcfa3a1dfffd2768ce605e4f7e30 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* QLogging: switch the systemd/journald sink to unformatted modeThiago Macieira2025-01-021-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | The extra information is already stored in the journal metadata anyway, so there's no need to duplicate it. This matches the Apple Unified Logger output now. For most people, the visible difference will be that the category name is not included in the plain "journalctl" output. Aug 22 21:25:43 tjmaciei-mobl5 akonadi_imap_resource[4948]: org.kde.pim.kimap: Connection to server lost QAbstractSocket::HostNotFoundError Aug 22 21:27:17 tjmaciei-mobl5 kwin_x11[3376]: kwin_core: XCB error: 3 (BadWindow), sequence: 41165, resource id: 29363347, major code: 129 (SHAPE), minor code:> journalctl does not make it easy to show extra fields, but it's there and can be retrieved with -o verbose. [ChangeLog][QtCore][Logging] The Qt logging framework (qDebug/qWarning/etc) will now only send the plain, unformatted message to systemd's journald, if this backend is enabled. The category and other fields are sent via metadata to journald, so they can be filtered on and retrieved using journalctl. This matches what Qt does for the Apple Logging support and does not apply when Qt is using syslog or stderr to communicate with journald. Change-Id: Ifa1111900d6945ea8e05fffd177de8f47d74ba60 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* Replace qgetenv() calls converted to QString with qEnvironmentVariable()Thiago Macieira2025-01-011-1/+1
| | | | | | | | It's slightly more efficient. Pick-to: 6.9 Change-Id: Id5ac04fc27eee108c8e5fffd786c3d5f793a0a9d Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Android: Fix typo in the documentation of the default log patternLars Schmertmann2024-12-101-1/+1
| | | | | | | | Pick-to: 6.9 6.8 6.5 Task-number: QTBUG-94708 Change-Id: I845f193f1b98219be205b8615f817f3315f4d149 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* Android: Fix logging of the categoryLars Schmertmann2024-11-261-8/+27
| | | | | | | | | | | | | | | | | 87d8ee755bfdef8e72a122789c2e3ed382881a12 changed the logging behavior on Android to use the category as tag. But it was missed that `formatLogMessage` only fills the fields given in the messagePattern. Our default messagePattern includes the category but on Android it is never filled since this change. So we change the default messagePattern on Android to omit the category and only use the category as tag when the category is not given in the messagePattern. Pick-to: 6.8 6.5 Task-number: QTBUG-94708 Change-Id: I80f65d0f7f8c0ca9c2fff2dcd63d4599848b6e2b Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
* wasm: Ifdef out unused function systemHasStderrTor Arne Vestbø2024-08-271-2/+2
| | | | | | Pick-to: 6.8 Change-Id: Ifae799d62668382c93ef85826b397f4a9d3e4199 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: link from non-categorized logging API to QLoggingCategoryVolker Hilsheimer2024-07-191-11/+19
| | | | | | | | | | | The <QtLogging> documentation page is easily found, and from there it's not easy to see that categorized logging is a feature. Add more links. Pick-to: 6.8 Task-number: QTBUG-125589 Change-Id: I214b9a561d6fc6b4c8600bc1b1eca04d856678d6 Reviewed-by: Safiyyah Moosa <safiyyah.moosa@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Remove QT_TERMINATE_ON_EXCEPTION: no longer neededThiago Macieira2024-05-311-3/+3
| | | | | | | | | | | | | | | | | When Marc introduced them way back in 2012 in commit c856e37c5fddec64d8635f3dae57b9cbea1aada4 ("Logging: mark qt_assert()/ qt_assert_x()/qFatal() as nothrow"), he said: > QT_TERMINATE_ON_EXCEPTION, which expands to something like > try { expr; } catch(...) { std::terminate(); } > if the compiler doesn't support Q_DECL_NOEXCEPT Well, all compilers now support noexcept, so we always had the plain do { } while (0) expansion instead. Change-Id: If3345151ddf84c43a4f1fffd17d27dbc0f100ec7 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Doc: Hint about QtMsgType orderKai Köhne2024-05-281-3/+1
| | | | | | | | | | | | | You could get the idea that the underlying int value is indicative of the severity. Make it more explicit that the order in the text is the correct one, and reorder for Qt 7. While at it, remove mentioning of Qt 5.5. Pick-to: 6.7 Fixes: QTBUG-102347 Change-Id: I5d1b46afb37e50baa209a06c192a943980ca774b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QLogging: enable %{backtrace} support via <stacktrace>Giuseppe D'Angelo2024-04-181-7/+68
| | | | | | | | | | | | | | | | | | | C++23 gave us a standardized way to gather backtraces, so we can use it to add cross-platform support for %{backtrace}. Guard the feature via a compile test; at the moment, this is enabled it on MSVC only. GCC has experimental support (requires linking against libstdc++exp), so it will still fail the test. [ChangeLog][QtCore][QDebug] Support for the %{backtrace} expansion has been extended to the platforms supporting C++23's <stacktrace> header (such as MSVC 2022 >= 17.4). Change-Id: I04d58a193384a61e4f8e6fef78286d4bad98a025 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* wasm: log using emscripten_log() by defaultMorten Sørvig2024-04-171-2/+7
| | | | | | | | | | | | | | | | | | Log using emscripten_log by default, unless QT_FORCE_STDERR_LOGGING has been set. It is now possible to log at different levels: qDebug() -> Info qWarning() -> Warning qCritical() -> Error #ifdef out functions which are now no longer in use on Q_OS_WASM Change-Id: I0485e5c070069998a8dfc6759c02bc3b7d6a8a4b Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QLogging: exclude QInternalMessageLogContext from backtracesGiuseppe D'Angelo2024-04-031-0/+2
| | | | | | | | | "Just in case" -- as the comment says, QInternalMessageLogContext's constructor is usually inlined, but we can't be sure if it has been. Change-Id: I4da2f0875d9fd9f7bd6d79447b4761fda329c7fd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Logging: capture the backtrace closer to the user's entry pointThiago Macieira2024-03-271-31/+81
| | | | | | | | | | | | | | | Instead of deep inside the processing of the message pattern tokens. This reduces the number of uninlineable functions in release builds to 2. Experimentation shows that even in debug mode our overhead to backtrace() is just 2, despite the debugger's backtrace showing 3 frames -- the debugger is using QtCore's debug symbols and does know about the inlined function. As a nice side-effect, we capture the backtrace only once per message, not once per %{backtrace} token in the QT_MESSAGE_PATTERN. Change-Id: I01ec3c774d9943adb903fffd17b7d6de09167620 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Logging: introduce QInternalMessageLogContext to hold current contextThiago Macieira2024-03-271-39/+25
| | | | | | | | | | | | | | QMessageLogContext is a primitive type that may be extended in the future with more fields (it has been at version 2 since commit 6d166c88220ee09821b65fb2b711fa77a5312971, though that did not extend the struct's size). This introduces a QInternalMessageLogContext which is used in before all our calls to qt_message_output(). Currently there's no difference and no way to tell that the internal version is used. Change-Id: I01ec3c774d9943adb903fffd17b7d5abc0052207 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* qErrnoWarning: downgrade from critical to warningDavid Faure2024-03-271-2/+2
| | | | | | | | | | | | | | | | | | The name says it's a warning, it's pretty unexpected that it should lead to a critical message. One case where this is a problem is QTBUG-48488 where merely printing with "Microsoft Print To PDF" and canceling the file dialog leads to "QWin32PrintEngine::begin: StartDoc failed" as a *critical* message. Some Windows applications have a message handler that shows a msgbox in case of a critical message, and getting such a msgbox after canceling the file dialog seems very wrong. Task-number: QTBUG-48488 Pick-to: 6.7 Change-Id: I1c842340dd2faf2be6e64e0522f9e2b33547d3cf Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove unnecessary #undef about q{Debug,Info,Warning,Critical,Fatal}Thiago Macieira2024-03-041-8/+0
| | | | | | | | | | | | | | | | | | The ones in qlogging.cpp were copied to it from qglobal.cpp in commit 23688d8942895507f4bc1517dd3c161134f4f9d0. They existed in qglobal.cpp like in qdebug.cpp since the beginning of the public history. The one in qdebug.cpp already made no sense in Qt 4 times, because qdebug.cpp was a documentation-only source (no actual C++ code). The #undefs from qglobal.cpp hadn't been necessary since commit d394ca7f27197cfbfc28eb9a08eb0db261dd9d3d, the global functions qDebug(), qWarning(), qCritical(), etc. were replaced by member functions in QMessageLogger whose names did not match the macros. Pick-to: 6.7 Change-Id: I50e2158aeade4256ad1dfffd17b1c62f23eca4db Reviewed-by: Kai Köhne <kai.koehne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QLogging: Add missing newline in win_message_handler()Johannes Grunenberg2024-02-061-1/+1
| | | | | | | | | | | | | Neither win_outputDebugString_helper() nor OutputDebugString() add a newline at the end of the message, so one needs to be added before being passed to the output handler. A newline was previously present but removed when deduplicating calls to qFormatLogMessage(). Fixes: QTBUG-121947 Pick-to: 6.7 Change-Id: I9f1c1d8726e4234f24999f47c52340140d5a4614 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLogging: disable the message pattern functionality for bootstrapThiago Macieira2023-10-241-14/+23
| | | | | | | | We only have two tools that use the Bootstrap lib and neither of them need nor want the message pattern functionality. Change-Id: Ifa1111900d6945ea8e05fffd177e191ebb6afc4f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* QLogging: call a non-exported message-formatting functionThiago Macieira2023-10-241-5/+14
| | | | | | | | | | | | | | Instead of the exported qFormatLogMessage() that users can use. Because it's a local symbol (static function), neither dladdr() nor backtrace_symbols() functions should be able to see them, making their exclusion from the list a simpler check. This doesn't apply when the user calls qFormatLogMessage() in their own handler, unless the compiler either inlines or tail-calls the new, internal function. The latter case is very likely. Change-Id: Ifa1111900d6945ea8e05fffd177e187f55512725 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* QMessagePattern: use the system message sinks for parsing errorsThiago Macieira2023-10-241-23/+24
| | | | | | | | | Instead of only printing to stderr or the Windows debug buffer. I guess this wasn't done before because the code could recurse back and cause stack overflows. We can do it now without recursion problems. Change-Id: Ifa1111900d6945ea8e05fffd177e14e2f86ae482 Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* QLogging: use stderr_message_handler() if we fail to grab the handlerThiago Macieira2023-10-241-1/+1
| | | | | | | | Instead of duplicating its stderr handling. Change-Id: Ifa1111900d6945ea8e05fffd177e149dfa9afff9 Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* QLogging: deduplicate the calls to qFormatLogMessage()Thiago Macieira2023-10-241-36/+44
| | | | | | | | | | | Lift it up from inside of each of the message sinks and instead perform the formatting in qDefaultMessageHandler(). This necessitated having a trait indicating whether the sink takes formatted output or not (currently, only the Apple backend is unformatted). Change-Id: Ifa1111900d6945ea8e05fffd177e155db9a599cc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* QLogging: simplify qDefaultMessageHandler() with a global constantThiago Macieira2023-10-241-24/+30
| | | | | | | | | | | Namely, a function pointer to the actual sink function. This doesn't remove the future ability to iterate over multiple sinks, but I removed the comment anyway because it doesn't look like we'll ever implement that. Change-Id: Ifa1111900d6945ea8e05fffd177de7fa46230259 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
* Doc: Improve documentation for qInstallMessageHandler()Kai Köhne2023-10-131-24/+51
| | | | | | | | | | | | | | | | | | Mention that QtMessageHandler needs to be reentrant, as well as other caveats. Mention QLoggingCategory, so people do know that they don't have to necessarily implement their own handler to filter messages (and that not all messages reach the handler). Also mention qFormatLogMessage(). Finally, give a more useful example for a custom message handler that logs to a file. Note that the example leaks a file handle at exit, but that is arguably not that bad. Pick-to: 6.5 6.6 Change-Id: I5be44167b266c9bbdbb0e94806bb024c9b352a32 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QLogging: attempt to free memory in qt_message() before abort()Thiago Macieira2023-09-091-4/+8
| | | | | | | | Just so memory leak checkers won't complain. Pick-to: 6.6 Change-Id: I2b24e1d3cad44897906efffd177fb9ddf0eb0a2a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>