Qt HTTP Server Registrazione
Qt HTTP Server registra i log utilizzando la classe QLoggingCategory. Le categorie di registrazione che iniziano con "qt.httpserver" sono utilizzate dalle diverse parti di Qt HTTP Server. Queste possono essere abilitate e disabilitate come descritto in QLoggingCategory.
Per abilitare o disabilitare dinamicamente ciò che viene registrato, chiamare QLoggingCategory::setFilterRules(). Un server può aggiungere un URL per modificare le regole di filtraggio, utilizzando la funzione QHttpServer::route() come mostrato di seguito.
#include <QCoreApplication>
#include <QHttpServer>
#include <QLoggingCategory>
int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);
QHttpServer server;
auto tcpserver = std::make_unique<QTcpServer>();
if (!tcpserver->listen(QHostAddress::LocalHost, 8000) || !server.bind(tcpserver.get()))
return -1;
tcpserver.release();
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();
}Le regole di filtraggio possono ora essere impostate utilizzando: ` "http://127.0.0.1:8000/loggingFilter?qt.httpserver=true&appname.access=true"`. In questo caso verrà abilitata tutta la registrazione tramite ` Qt HTTP Server ` e, inoltre, verrà abilitata l’ipotetica categoria di registrazione ` appname.access `.
Vedi anche QLoggingCategory e QHttpServer.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.