Where is located the qDebug qWarning qCritical and qFatal log by default on Qt?
Asked Answered
L

4

2

When running my Qt5 application on linux, I don't see any output from qDebug, qWarning, qCritical or qFatal. I know that I can use qInstallMsgHandler to install a message handler and see them, but this is rather heavyweight.

I just want to check the qWarning log to see if there is any signal that mis-connected. Is there a way to look at this log? A special command-line option, an environment variable?

I think I remember that in the past, everything was printed to stderr, perhaps that's a Qt5 change?

Landlocked answered 10/10, 2014 at 8:44 Comment(0)
H
17

Please do not make the mistake of assuming that qDebug, qWarning, qCritical and qFatal always log on standard error. That's absolutely not the case.

The actual destination varies depending on the Qt configuration and the targeting OS. Plus, 5.4 and then 5.11 introduced some behavioural changes. See here and here for discussions.

TL;DR:

On Qt >= 5.11

  • If the process' stderr has a console attached, that's where the debug log will go.
  • If you want to always log on stderr, set QT_FORCE_STDERR_LOGGING to 1.
  • In alternative, set QT_ASSUME_STDERR_HAS_CONSOLE to 1. I suspect this one is meant to be used by a parent process that reads a child's stderr and shows it to the user somehow.
  • QT_LOGGING_TO_CONSOLE to 1 still works, but Qt will complain.

On Qt >= 5.4 and < 5.11

  • If you want to always log on stderr, set the QT_LOGGING_TO_CONSOLE environment variable to 1.
  • If you do not want to log on stderr, the QT_LOGGING_TO_CONSOLE environment variable to 0 (this will force logging through the native system logger).
  • If the QT_LOGGING_TO_CONSOLE environment variable is not set, then whether logging to the console or not depends on whether the application is running in a TTY (on UNIX) or whether there's a console window (on Windows).

On Qt < 5.4, the situation is more confusing.

  • If Qt has been built with support for a specific logging framework (e.g. SLOG2, journald, Android log, etc.) then logging always goes to that framework
  • Otherwise on UNIX it goes to stderr
  • Otherwise on Windows OutputDebugString or stderr is used depending whether the app is a console app.

The problem with the pre-5.4 approach was that, f.i., under Unix IDEs would not capture an application's debug output if Qt had been built with journald support. That's because the output went to journald, not to the IDE. In 5.4 the approach has been made more flexible and uniform across OSes.

Hue answered 12/10, 2014 at 13:40 Comment(3)
This is as you says except that QT_LOGGING_TO_CONSOLE seem to work with Qt 5.3.2 (as packaged by ArchLinux)Landlocked
Maybe Arch backported the patches? See the discussion in this bug report bugs.archlinux.org/task/40583Hue
I only found this after finding the answer elsewhere on Arch linux forums, but the answer is perfect. My question was more "why did qDebug() stop going to console after upgrade Qt (past 5.3)?" This thread should be referenced from a bunch of other stackoverflow questions.Claudieclaudina
H
5

If you happen to run Arch Linux, which compiles Qt with the -journald option, all debug output is per default directed to the systemd journal (display with journalctl).

You can override this behaviour by defining QT_LOGGING_TO_CONSOLE=1 as an environment variable.

Havelock answered 10/10, 2014 at 11:28 Comment(1)
QT_LOGGING_TO_CONSOLE is currently deprecated as @Hue already said in his answer (QtCreator >5.15). Using the QT_ASSUME_STDERR_HAS_CONSOLE=1 environment variable and starting QtCreator from terminal, makes the output to be printed on Arch. See: bbs.archlinux.org/viewtopic.php?id=259035 for further info about the issueFetish
D
1

They are still printed to standard error.

If you launch the application from the command line, it is usually printed there, or if using Qt Creator, it's displayed in the Application Output window.

Domela answered 10/10, 2014 at 8:50 Comment(0)
S
0

If you are using visual studio, qDebug etc are printed to the output window in the IDE.

Stole answered 10/10, 2014 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.