commit 45ea045f54d365087cb301965fbc33e8bc2b18b1 from: Aleksey Ryndin date: Mon Apr 22 09:44:27 2024 UTC Refactoring of logging commit - f75e0f1a72dbf7c35a7025aa53287d5c8c1af5a7 commit + 45ea045f54d365087cb301965fbc33e8bc2b18b1 blob - 80f5fd39ef57ac01af4d912703a1fab13a12890e blob + 341cc92532e6ef1ef93de4c2dd90850a57ef276d --- vostok/vostok.cc +++ vostok/vostok.cc @@ -58,6 +58,14 @@ bool send_response(NotNull ctx, gemini:: void client_thread(const transport::AcceptedClient *accepted_client, int directory_fd, const Mime &mime) { + struct LogThreadId + { + LogThreadId() {error::g_log << "+" << std::hex << m_thread_id << " ";} + ~LogThreadId() { error::g_log << "-" << std::hex << m_thread_id << std::endl;} + + const std::thread::id m_thread_id{std::this_thread::get_id()}; + } log_thread_id; + assert(accepted_client); std::unique_ptr accepted_client_deleter{accepted_client}; @@ -67,14 +75,17 @@ void client_thread(const transport::AcceptedClient *ac std::string path; const auto parse_result = request.parse(path); + if (parse_result != Request::URL_OK) + { + error::g_log << "\""; + for (const auto byte : request.m_buffer) + error::g_log << "\\x" << std::hex << static_cast(byte); + error::g_log << "\" "; + } switch (parse_result) { case Request::BAD_REQUEST: error::occurred("Parse request", []{error::g_log << meta::BAD_REQUEST;}); - error::g_log << std::dec << request.m_buffer.size(); - for (const auto byte : request.m_buffer) - error::g_log << " 0x" << std::hex << static_cast(byte); - error::g_log << std::endl; send_response(accepted_client->get_ctx(), gemini::STATUS_59_BAD_REQUEST, meta::BAD_REQUEST); return; case Request::URL_TOO_SHORT: @@ -83,10 +94,6 @@ void client_thread(const transport::AcceptedClient *ac return; case Request::URL_NON_GEMINI: error::occurred("Parse request", []{error::g_log << meta::NON_GEMINI;}); - error::g_log << std::dec << request.m_buffer.size(); - for (const auto byte : request.m_buffer) - error::g_log << " 0x" << std::hex << static_cast(byte); - error::g_log << std::endl; send_response(accepted_client->get_ctx(), gemini::STATUS_53_PROXY_REQUEST_REFUSED, meta::NON_GEMINI); return; case Request::URL_ROOT_TRAVERSE: