Strip trailing newline from timestamp

This commit is contained in:
apio 2022-11-04 20:24:32 +01:00
parent e657640409
commit 1c8287d80f

View File

@ -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) { void webcxx::Request::log(int status_code) {
time_t current_time = time(NULL); time_t current_time = time(NULL);
printf("(%s) %s - \"%s %s HTTP/1.1\" - %d\n", ctime(&current_time), m_ip.c_str(), printf("(%s) %s - \"%s %s HTTP/1.1\" - %d\n", remove_trailing_newline(ctime(&current_time)).c_str(), m_ip.c_str(),
method_to_string(m_method).c_str(), method_to_string(m_method).c_str(),
m_real_path.c_str(), m_real_path.c_str(),
status_code); status_code);