- Qt 6.6
- Qt HTTP Server
- Qt HTTP Server Logging
- Qt 6.6.0 Reference Documentation

# Qt HTTP Server Logging

The Qt HTTP Server logs using the QLoggingCategory class. The logging categories starting with "qt.httpserver" are used by the different parts of the Qt Http Server. These can be enabled and disabled as described in QLoggingCategory.

To dynamically enable or disable what is being logged call QLoggingCategory::setFilterRules(). A server can add a URL to change the filter rules, by using the QHttpServer::route() function as shown below.

     #include <QCoreApplication>
     #include <QHttpServer>
     #include <QLoggingCategory>

     int main(int argc, char** argv)
     {
         QCoreApplication app(argc, argv);
         QHttpServer server;
         server.listen(QHostAddress::LocalHost, 8000);

         server.route("/loggingFilter", [] (const QHttpServerRequest &request) {
             QString filter;
             QTextStream result(&filter);
             for (auto pair : request.query().queryItems()) {
                 if (!filter.isEmpty())
                     result << "\n";
                 result << pair.first << "=" << pair.second;
             }
             QLoggingCategory::setFilterRules(filter);
             return filter;
         });

         return app.exec();
     }

The filter rules can now be set using: "http://127.0.0.1:8000/loggingFilter?qt.httpserver=true&appname.access=true". In this case all Qt HTTP Server logging will be enabled, and in addition the hypothetical logging category "appname.access" is enabled.

See also QLoggingCategory and QHttpServer.