Merge pull request #7922 from Icinga/feature/http-status-codes-in-icinga-mainlog-7053

Include HTTP status codes in log
This commit is contained in:
Julian Brost 2020-11-24 16:35:58 +01:00 committed by GitHub
commit 2a2924855f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -539,12 +539,16 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
authenticatedUser = ApiUser::GetByAuthHeader(request[http::field::authorization].to_string());
}
Log(LogInformation, "HttpServerConnection")
<< "Request: " << request.method_string() << ' ' << request.target()
Log logMsg (LogInformation, "HttpServerConnection");
logMsg << "Request: " << request.method_string() << ' ' << request.target()
<< " (from " << m_PeerAddress
<< "), user: " << (authenticatedUser ? authenticatedUser->GetName() : "<unauthenticated>")
<< ", agent: " << request[http::field::user_agent] << ")."; //operator[] - Returns the value for a field, or "" if it does not exist.
<< ", agent: " << request[http::field::user_agent]; //operator[] - Returns the value for a field, or "" if it does not exist.
Defer addRespCode ([&response, &logMsg]() {
logMsg << ", status: " << response.result() << ").";
});
if (!HandleAccessControl(*m_Stream, request, response, yc)) {
break;