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 &
amp;request) {
QString filter;
QTextStream result(&
amp;filter);
for
(auto
pair : request.query().queryItems()) {
if
(!
filter.isEmpty())
result &
lt;&
lt; "
\n
"
;
result &
lt;&
lt; pair.first &
lt;&
lt; "="
&
lt;&
lt; 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▲
See also QLoggingCategory, QHttpServer