From 27cf2123e5710c9fb603c1f58e870ecf8a8c2feb Mon Sep 17 00:00:00 2001 From: Marcin Siodelski Date: Tue, 29 May 2018 16:08:03 +0200 Subject: [5205] Improved HTTP server side logging. --- src/lib/http/connection.cc | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src/lib/http/connection.cc') diff --git a/src/lib/http/connection.cc b/src/lib/http/connection.cc index c6f3f36caa..11a272a03a 100644 --- a/src/lib/http/connection.cc +++ b/src/lib/http/connection.cc @@ -13,6 +13,15 @@ using namespace isc::asiolink; +namespace { + +/// @brief Maximum size of the HTTP message that can be logged. +/// +/// The part of the HTTP message beyond this value is truncated. +constexpr size_t MAX_LOGGED_MESSAGE_SIZE = 1024; + +} + namespace isc { namespace http { @@ -203,12 +212,28 @@ HttpConnection::socketReadCallback(boost::system::error_code ec, size_t length) doRead(); } else { - LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_DETAIL, - HTTP_REQUEST_RECEIVED) - .arg(getRemoteEndpointAddressAsText()); try { request_->finalize(); - } catch (...) { + + LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_BASIC, + HTTP_REQUEST_RECEIVED) + .arg(getRemoteEndpointAddressAsText()); + + LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_BASIC_DATA, + HTTP_REQUEST_DETAILS) + .arg(getRemoteEndpointAddressAsText()) + .arg(parser_->getBufferAsString(MAX_LOGGED_MESSAGE_SIZE)); + + } catch (const std::exception& ex) { + LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_BASIC, + HTTP_BAD_REQUEST_RECEIVED) + .arg(getRemoteEndpointAddressAsText()) + .arg(ex.what()); + + LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_BASIC_DATA, + HTTP_BAD_REQUEST_DETAILS) + .arg(getRemoteEndpointAddressAsText()) + .arg(parser_->getBufferAsString(MAX_LOGGED_MESSAGE_SIZE)); } HttpResponsePtr response = response_creator_->createHttpResponse(request_); @@ -216,6 +241,13 @@ HttpConnection::socketReadCallback(boost::system::error_code ec, size_t length) HTTP_RESPONSE_SEND) .arg(response->toBriefString()) .arg(getRemoteEndpointAddressAsText()); + + LOG_DEBUG(http_logger, isc::log::DBGLVL_TRACE_DETAIL_DATA, + HTTP_RESPONSE_DETAILS) + .arg(getRemoteEndpointAddressAsText()) + .arg(HttpMessageParserBase::logFormatHttpMessage(response->toString(), + MAX_LOGGED_MESSAGE_SIZE)); + asyncSendResponse(response); } } -- cgit v1.2.3