From 1c8287d80f528e6ce17e05bea8737943b544a7f4 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 4 Nov 2022 20:24:32 +0100 Subject: [PATCH] Strip trailing newline from timestamp --- src/Request.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Request.cpp b/src/Request.cpp index f0a46c6..76b882c 100644 --- a/src/Request.cpp +++ b/src/Request.cpp @@ -144,9 +144,18 @@ static std::string method_to_string(webcxx::RequestType method) { } } +static std::string remove_trailing_newline(std::string str) +{ + while(str[str.size() - 1] == '\n') + { + str.pop_back(); + } + return std::move(str); +} + void webcxx::Request::log(int status_code) { time_t current_time = time(NULL); - printf("(%s) %s - \"%s %s HTTP/1.1\" - %d\n", ctime(¤t_time), m_ip.c_str(), + printf("(%s) %s - \"%s %s HTTP/1.1\" - %d\n", remove_trailing_newline(ctime(¤t_time)).c_str(), m_ip.c_str(), method_to_string(m_method).c_str(), m_real_path.c_str(), status_code);