34 lines
895 B
C++
34 lines
895 B
C++
#include "RequestLogger.h"
|
|
|
|
#include <drogon/drogon.h>
|
|
|
|
namespace
|
|
{
|
|
const auto registeredClassName = RequestLogger::classTypeName();
|
|
}
|
|
|
|
void RequestLogger::initAndStart(const Json::Value &config)
|
|
{
|
|
includeQuery_ = config.get("include_query", true).asBool();
|
|
LOG_INFO << "RequestLogger plugin initialized";
|
|
|
|
drogon::app().registerPreSendingAdvice(
|
|
[this](const drogon::HttpRequestPtr &req,
|
|
const drogon::HttpResponsePtr &resp) {
|
|
auto url = req->path();
|
|
if (includeQuery_ && !req->query().empty())
|
|
{
|
|
url += "?";
|
|
url += req->query();
|
|
}
|
|
|
|
LOG_INFO << req->methodString() << " " << url << " -> "
|
|
<< static_cast<int>(resp->statusCode()) << " from "
|
|
<< req->getPeerAddr().toIpPort();
|
|
});
|
|
}
|
|
|
|
void RequestLogger::shutdown()
|
|
{
|
|
}
|