Qt HTTP Server ロギング
Qt HTTP Server は、QLoggingCategory クラスを使用してログを記録します。"qt.httpserver" で始まるロギングカテゴリは、Qt HTTP Serverの各部分で使用されます。これらのカテゴリは、QLoggingCategory に記載されている手順に従って有効化または無効化できます。
ログの記録内容を動的に有効または無効にするには、QLoggingCategory::setFilterRules() を呼び出します。サーバーは、以下に示すようにQHttpServer::route() 関数を使用して、フィルタルールを変更するための URL を追加できます。
#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();
}これで、"http://127.0.0.1:8000/loggingFilter?qt.httpserver=true&appname.access=true" を使用してフィルタルールを設定できるようになります。この場合、Qt HTTP Server によるすべてのログ記録が有効になり、さらに架空のログカテゴリappname.access も有効になります。
「 QLoggingCategory 」および「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.