Improve logging
Open, NormalPublic

Description

Krita makes extensive use of Qt's logging facilities, and right now it can be a bit awkward to obtain and filter log data. With the incoming Python scripting support, we will have a new category of power users; script/plugin developers. These users are developers that may not have access to a full C++ development environment, and so it's even more important that logs are easily accessible outside of debug sessions.

We should still try to keep the current logging output intact, so QT_LOGGING_RULES and others can continue to control the debug output being logged to console or DebugView.

To this end, we need:

  • A hook into Qt's logging facilities
  • A hook into Python's logging facilities
  • Some way to filter logs
  • A UI where relevant logs are presented

Use-cases:

  • Bug reporting (tablet logs, broken scripts, etc.)
  • Python script development
victorw created this task.Aug 13 2017, 4:27 PM
Restricted Application added a subscriber: woltherav. · View Herald TranscriptAug 13 2017, 4:27 PM
alvinhochun updated the task description. (Show Details)Aug 13 2017, 4:34 PM

I've implemented a basic KisLogManager class with the ability to capture logging messages. It can be extended for use.

It already has the code to configure QLoggingCategory filters and get the logging messages, but more work is needed before it can be made more useful. Thread-safety is also not considered in the current code.

The relevant commit is 221f6415076c096bc7b68b60600d813d231547ec and it is on branch alvin/logging-capture. You can fork a branch off it and start working from there.

P.S. Here is a sample code snippet on using the current log capturing code:

{
    qDebug() << "test log capturing";
    QString dbgStr;
    QDebug dbg(&dbgStr);
    KisLoggingManager::ScopedLogCapturer logCapturer("qt.qpa.gl",
        [&dbg](QtMsgType type, const QMessageLogContext &context, const QString &msg) {
            dbg << "Captured Message type:" << type << ", Context:" << context.category << context.file << context.function << context.line << context.version << ", msg:" << msg;
            dbg << "\n";
        });
    {
        QGuiApplication app(argc, argv);
    }
    qDebug() << "Captured:\n" << dbgStr;
}

To manage the lifecycle a bit better, perhaps KisLoggingManager should be changed to a global "singleton"-like object initialized as a local variable within main(). This way it can automatically perform initialization and cleanup via the constructor and destructor, and reduce the amount of global static variables to just one.

woltherav moved this task from Backlog to Zeyelth on the Krita board.May 18 2018, 9:06 AM