Skip to content

Capturing Qt logging #39

Closed
Closed
@The-Compiler

Description

@The-Compiler

Continuing the discussion from hackebrot/qutebrowser#8 (comment) here 😄

I agree it's a good idea to do a fixture similiar to caplog, with a .records() and maybe .setLevel() and .atLevel() as well.

Levels of messages

In Qt, there are the following logging "levels"/functions - I also checked how much it's used in the whole qtbase sourcecode:

  • qFatal(): An error which means any further execution of the application is useless. Calls abort() immediately by default, so probably should never be captured as we'll not get to the point to display the captured output. Used 178 times, for things like when no screen was found, or you're mixing incompatible Qt libraries.
  • qCritical(): A critical issue. Qt should IMHO use this for many things which are actually only qWarnings, but it's only used 88 times.
  • qWarning(): Used for a lot of messages which aren't really "just warnings", but Qt is (or thinks it is) able to recover from. Used 2601 times.
  • qDebug(): Used for debug output (1692 times), but only if you recompile Qt yourself with -debug.

Handling of qFatal()

As said I think this should not be captured. The Qt documentation says:

If you are using the default message handler this function will abort on Unix systems to create a core dump. On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application.

I wonder how this should be handled, as it's probably a good idea to keep that behaviour. Maybe disable the custom message handler from inside it, and then call qFatal() with the given message again?

Other levels

I think qCritical() / qWarning() / qDebug() should all be captured and printed with failed tests by default.

However as said, I'd also like to have a way to always print qCritical()/qWarning(). Maybe some --qt-log-always option, and a --qt-log-format option so I can get it in the format I want?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions