[Development] Cake and eating it too for qDebug printing to system log - https://codereview.qt-project.org/89357

Thiago Macieira thiago.macieira at intel.com
Thu Jul 10 01:15:16 CEST 2014

On Wednesday 09 July 2014 14:43:36 Thiago Macieira wrote:
> === Log to system logs only ===
> This causes reports like [4]. But note that the bug is actually in Creator, 
> for failing to read the log store and display the data, like it does on
> Windows with the debug output.
> This is an option.
> === Heuristically determine at runtime where to send the log ===
> Which is what I'm trying to do above.
> On Windows, we check whether we have a console and whether stderr is not
> NUL.
> On Unix, I have implemented the same checks.
> We can also use the fact of whether the main application is in debug mode
> or  not.

Here's what I propose:

Heuristically determine at runtime. On all platforms (including Windows), use 
only the fact that a terminal is present. If a terminal is present, write to 
it using stderr. Otherwise, write to the system log.

* Implications for Qt Creator:
1) it must be able to read from the system log for desktop debugging 
(especially when running applications without "Run in terminal"). That's 
already done on Windows. It will be necessary to add support for journald 
(Linux) and asl (OS X).

2) remote debugging: per platform, it needs to be decided whether we can 
access the log on the remote device. If so, that's the best situation. If it 
isn't, then we need to force Qt to log to stderr.

 2a) set QT_LOGGING_TO_CONSOLE=1 in the environment
 2b) force the allocation of a terminal (if using ssh, pass the -t option)

I recommend advising Linux distributions to disable journald logging at least 
until Creator is updated. And the support for asl on OSX should be held until 
the same time.

* Implications for unit tests:
Except for the unit tests testing logging to the system log in the first place, 
QT_LOGGING_TO_CONSOLE=1 should be set. I think QtTest itself should do that.

* Support for journald in the pre-built Creator binary:
1) new plugin, link to libsystemd-journal.so.0. If the library isn't present 
in the target system, the plugin won't load.

2) dlopen libsystemd-journal.so.0. If it isn't present, then Qt can't very 
well be logging to it.

3) use QProcess to run journalctl -f

* Support for journald in the pre-built Qt binaries:
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Development mailing list