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も参照のこと 。
© 2025 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.