IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Qt HTTP Server Logging

Shows how the QtHttpServer module logging can be configured.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

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.

 
Sélectionnez
#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

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+