summaryrefslogtreecommitdiff
path: root/http/server_sent_event.hpp
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2023-07-18 03:06:25 +0300
committerEd Tanous <ed@tanous.net>2023-07-20 01:38:41 +0300
commit62598e31d0988d589506d5091bd38f72d61faf5e (patch)
treee3e548632da934083c21cc1262f8b9d8f255f2a9 /http/server_sent_event.hpp
parent609ba4c9ffb9c6b83861ff557108c89007ca369a (diff)
downloadbmcweb-62598e31d0988d589506d5091bd38f72d61faf5e.tar.xz
Replace logging with std::format
std::format is a much more modern logging solution, and gives us a lot more flexibility, and better compile times when doing logging. Unfortunately, given its level of compile time checks, it needs to be a method, instead of the stream style logging we had before. This requires a pretty substantial change. Fortunately, this change can be largely automated, via the script included in this commit under scripts/replace_logs.py. This is to aid people in moving their patchsets over to the new form in the short period where old patches will be based on the old logging. The intention is that this script eventually goes away. The old style logging (stream based) looked like. BMCWEB_LOG_DEBUG << "Foo " << foo; The new equivalent of the above would be: BMCWEB_LOG_DEBUG("Foo {}", foo); In the course of doing this, this also cleans up several ignored linter errors, including macro usage, and array to pointer deconstruction. Note, This patchset does remove the timestamp from the log message. In practice, this was duplicated between journald and bmcweb, and there's no need for both to exist. One design decision of note is the addition of logPtr. Because the compiler can't disambiguate between const char* and const MyThing*, it's necessary to add an explicit cast to void*. This is identical to how fmt handled it. Tested: compiled with logging meson_option enabled, and launched bmcweb Saw the usual logging, similar to what was present before: ``` [Error include/webassets.hpp:60] Unable to find or open /usr/share/www/ static file hosting disabled [Debug include/persistent_data.hpp:133] Restored Session Timeout: 1800 [Debug redfish-core/include/event_service_manager.hpp:671] Old eventService config not exist [Info src/webserver_main.cpp:59] Starting webserver on port 18080 [Error redfish-core/include/event_service_manager.hpp:1301] inotify_add_watch failed for redfish log file. [Info src/webserver_main.cpp:137] Start Hostname Monitor Service... ``` Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: I86a46aa2454be7fe80df608cb7e5573ca4029ec8
Diffstat (limited to 'http/server_sent_event.hpp')
-rw-r--r--http/server_sent_event.hpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/http/server_sent_event.hpp b/http/server_sent_event.hpp
index 02af0b7523..773394836f 100644
--- a/http/server_sent_event.hpp
+++ b/http/server_sent_event.hpp
@@ -49,7 +49,7 @@ class ConnectionImpl : public Connection
timer(ioc), openHandler(std::move(openHandlerIn)),
closeHandler(std::move(closeHandlerIn))
{
- BMCWEB_LOG_DEBUG << "SseConnectionImpl: SSE constructor " << this;
+ BMCWEB_LOG_DEBUG("SseConnectionImpl: SSE constructor {}", logPtr(this));
}
ConnectionImpl(const ConnectionImpl&) = delete;
@@ -59,7 +59,7 @@ class ConnectionImpl : public Connection
~ConnectionImpl() override
{
- BMCWEB_LOG_DEBUG << "SSE ConnectionImpl: SSE destructor " << this;
+ BMCWEB_LOG_DEBUG("SSE ConnectionImpl: SSE destructor {}", logPtr(this));
}
boost::asio::io_context& getIoContext() override
@@ -72,7 +72,7 @@ class ConnectionImpl : public Connection
{
if (!openHandler)
{
- BMCWEB_LOG_CRITICAL << "No open handler???";
+ BMCWEB_LOG_CRITICAL("No open handler???");
return;
}
openHandler(*this);
@@ -85,13 +85,13 @@ class ConnectionImpl : public Connection
{
closeHandler(*this);
}
- BMCWEB_LOG_DEBUG << "Closing SSE connection " << this << " - " << msg;
+ BMCWEB_LOG_DEBUG("Closing SSE connection {} - {}", logPtr(this), msg);
boost::beast::get_lowest_layer(adaptor).close();
}
void sendSSEHeader()
{
- BMCWEB_LOG_DEBUG << "Starting SSE connection";
+ BMCWEB_LOG_DEBUG("Starting SSE connection");
using BodyType = boost::beast::http::buffer_body;
boost::beast::http::response<BodyType> res(
boost::beast::http::status::ok, 11, BodyType{});
@@ -113,11 +113,11 @@ class ConnectionImpl : public Connection
serializer.reset();
if (ec)
{
- BMCWEB_LOG_ERROR << "Error sending header" << ec;
+ BMCWEB_LOG_ERROR("Error sending header{}", ec);
close("async_write_header failed");
return;
}
- BMCWEB_LOG_DEBUG << "SSE header sent - Connection established";
+ BMCWEB_LOG_DEBUG("SSE header sent - Connection established");
serializer.reset();
@@ -138,7 +138,7 @@ class ConnectionImpl : public Connection
}
if (ec)
{
- BMCWEB_LOG_ERROR << "Read error: " << ec;
+ BMCWEB_LOG_ERROR("Read error: {}", ec);
}
close("Close SSE connection");
@@ -152,7 +152,7 @@ class ConnectionImpl : public Connection
}
if (inputBuffer.size() == 0)
{
- BMCWEB_LOG_DEBUG << "inputBuffer is empty... Bailing out";
+ BMCWEB_LOG_DEBUG("inputBuffer is empty... Bailing out");
return;
}
startTimeout();
@@ -179,19 +179,19 @@ class ConnectionImpl : public Connection
if (ec == boost::asio::error::eof)
{
- BMCWEB_LOG_ERROR << "async_write_some() SSE stream closed";
+ BMCWEB_LOG_ERROR("async_write_some() SSE stream closed");
close("SSE stream closed");
return;
}
if (ec)
{
- BMCWEB_LOG_ERROR << "async_write_some() failed: " << ec.message();
+ BMCWEB_LOG_ERROR("async_write_some() failed: {}", ec.message());
close("async_write_some failed");
return;
}
- BMCWEB_LOG_DEBUG << "async_write_some() bytes transferred: "
- << bytesTransferred;
+ BMCWEB_LOG_DEBUG("async_write_some() bytes transferred: {}",
+ bytesTransferred);
doWrite();
}
@@ -200,7 +200,7 @@ class ConnectionImpl : public Connection
{
if (msg.empty())
{
- BMCWEB_LOG_DEBUG << "Empty data, bailing out.";
+ BMCWEB_LOG_DEBUG("Empty data, bailing out.");
return;
}
@@ -249,22 +249,24 @@ class ConnectionImpl : public Connection
std::shared_ptr<Connection> self = weakSelf.lock();
if (!self)
{
- BMCWEB_LOG_CRITICAL << self << " Failed to capture connection";
+ BMCWEB_LOG_CRITICAL("{} Failed to capture connection",
+ logPtr(self.get()));
return;
}
if (ec == boost::asio::error::operation_aborted)
{
- BMCWEB_LOG_DEBUG << "operation aborted";
+ BMCWEB_LOG_DEBUG("operation aborted");
// Canceled wait means the path succeeeded.
return;
}
if (ec)
{
- BMCWEB_LOG_CRITICAL << self << " timer failed " << ec;
+ BMCWEB_LOG_CRITICAL("{} timer failed {}", logPtr(self.get()), ec);
}
- BMCWEB_LOG_WARNING << self << "Connection timed out, closing";
+ BMCWEB_LOG_WARNING("{}Connection timed out, closing",
+ logPtr(self.get()));
self->close("closing connection");
}