Don't rely on operator << for object logging
In the upcoming fmt patch, we remove the use of streams, and a number of
our logging statements are relying on them. This commit changes them to
no longer rely on operator>> or operator+ to build their strings. This
alone isn't very useful, but in the context of the next patch makes the
automation able to do a complete conversion of all log statements
automatically.
Tested: enabled logging on local and saw log statements print to console
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I0e5dc2cf015c6924037e38d547535eda8175a6a1
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 5f352d3..1664d01 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -120,13 +120,15 @@
const boost::asio::ip::tcp::endpoint& endpoint) {
if (ec)
{
- BMCWEB_LOG_ERROR << "Connect " << endpoint
+ BMCWEB_LOG_ERROR << "Connect "
+ << endpoint.address().to_string()
<< " failed: " << ec.message();
self->state = ConnState::connectFailed;
self->handleConnState();
return;
}
- BMCWEB_LOG_DEBUG << "Connected to: " << endpoint;
+ BMCWEB_LOG_DEBUG << "Connected to: "
+ << endpoint.address().to_string();
self->state = ConnState::connected;
self->handleConnState();
});
@@ -186,7 +188,7 @@
BMCWEB_LOG_DEBUG << "recvMessage() bytes transferred: "
<< bytesTransferred;
BMCWEB_LOG_DEBUG << "recvMessage() data: "
- << self->parser->get();
+ << self->parser->get().body();
unsigned int respCode = self->parser->get().result_int();
BMCWEB_LOG_DEBUG << "recvMessage() Header Response Code: "
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index 6a874a7..42f2e53 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -343,7 +343,7 @@
<< " " << this << " HTTP/" << thisReq.version() / 10
<< "." << thisReq.version() % 10 << ' '
<< thisReq.methodString() << " " << thisReq.target()
- << " " << thisReq.ipAddress;
+ << " " << thisReq.ipAddress.to_string();
res.setCompleteRequestHandler(nullptr);
res.isAliveHelper = [this]() -> bool { return isAlive(); };
diff --git a/http/http_server.hpp b/http/http_server.hpp
index bf4a091..0b2cae1 100644
--- a/http/http_server.hpp
+++ b/http/http_server.hpp
@@ -91,7 +91,7 @@
};
BMCWEB_LOG_INFO << "bmcweb server is running, local endpoint "
- << acceptor->local_endpoint();
+ << acceptor->local_endpoint().address().to_string();
startAsyncWaitForSignal();
doAccept();
}
@@ -115,7 +115,7 @@
fs::create_directories(certPath);
}
fs::path certFile = certPath / "server.pem";
- BMCWEB_LOG_INFO << "Building SSL Context file=" << certFile;
+ BMCWEB_LOG_INFO << "Building SSL Context file=" << certFile.string();
std::string sslPemFile(certFile);
ensuressl::ensureOpensslKeyPresentAndValid(sslPemFile);
std::shared_ptr<boost::asio::ssl::context> sslContext =
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index 0945001..7387f4d 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -89,7 +89,8 @@
return;
}
endpoint.port(portNum);
- BMCWEB_LOG_DEBUG << "resolved endpoint is : " << endpoint;
+ BMCWEB_LOG_DEBUG << "resolved endpoint is : "
+ << endpoint.address().to_string();
endpointList.push_back(endpoint);
}
// All the resolved data is filled in the endpointList
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index a9e0ec4..8e30746 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -136,7 +136,7 @@
// Form the file path
loc /= fileID;
- BMCWEB_LOG_DEBUG << "Writing to the file: " << loc;
+ BMCWEB_LOG_DEBUG << "Writing to the file: " << loc.string();
// Check if the same file exists in the directory
bool fileExists = std::filesystem::exists(loc, ec);
@@ -305,7 +305,7 @@
"/var/lib/bmcweb/ibm-management-console/configfiles/" + fileID);
if (!std::filesystem::exists(loc))
{
- BMCWEB_LOG_ERROR << loc << "Not found";
+ BMCWEB_LOG_ERROR << loc.string() << "Not found";
asyncResp->res.result(boost::beast::http::status::not_found);
asyncResp->res.jsonValue["Description"] = resourceNotFoundMsg;
return;
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 9f84309..af6a720 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -2227,7 +2227,7 @@
if (!std::filesystem::exists(loc) ||
!std::filesystem::is_directory(loc))
{
- BMCWEB_LOG_ERROR << loc << "Not found";
+ BMCWEB_LOG_ERROR << loc.string() << "Not found";
asyncResp->res.result(
boost::beast::http::status::not_found);
return;
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 8f41f2f..36c3f8d 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -57,7 +57,7 @@
std::filesystem::recursive_directory_iterator dirIter(rootpath, ec);
if (ec)
{
- BMCWEB_LOG_ERROR << "Unable to find or open " << rootpath
+ BMCWEB_LOG_ERROR << "Unable to find or open " << rootpath.string()
<< " static file hosting disabled";
return;
}
@@ -117,7 +117,7 @@
{
// Got a duplicated path. This is expected in certain
// situations
- BMCWEB_LOG_DEBUG << "Got duplicated path " << webpath;
+ BMCWEB_LOG_DEBUG << "Got duplicated path " << webpath.string();
continue;
}
const char* contentType = nullptr;
@@ -137,7 +137,7 @@
if (contentType == nullptr)
{
BMCWEB_LOG_ERROR << "Cannot determine content-type for "
- << absolutePath << " with extension "
+ << absolutePath.string() << " with extension "
<< extension;
}
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 889f606..6d17a61 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -164,20 +164,22 @@
std::ofstream::trunc);
out << certString;
out.close();
- BMCWEB_LOG_DEBUG << "Creating certificate file" << certificateFile;
+ BMCWEB_LOG_DEBUG << "Creating certificate file"
+ << certificateFile.string();
}
}
~CertificateFile()
{
if (std::filesystem::exists(certDirectory))
{
- BMCWEB_LOG_DEBUG << "Removing certificate file" << certificateFile;
+ BMCWEB_LOG_DEBUG << "Removing certificate file"
+ << certificateFile.string();
std::error_code ec;
std::filesystem::remove_all(certDirectory, ec);
if (ec)
{
BMCWEB_LOG_ERROR << "Failed to remove temp directory"
- << certDirectory;
+ << certDirectory.string();
}
}
}
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index acaa40a..b0e2507 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1872,8 +1872,8 @@
return;
}
- BMCWEB_LOG_DEBUG
- << "Setting firmware version " + firmwareId + " to priority 0.";
+ BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId
+ << " to priority 0.";
// Only support Immediate
// An addition could be a Redfish Setting like
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 6c61e40..841463a 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -927,8 +927,8 @@
}
if (!found)
{
- BMCWEB_LOG_ERROR
- << "Input swID " + *swId + " not found!";
+ BMCWEB_LOG_ERROR << "Input swID " << *swId
+ << " not found!";
messages::resourceMissingAtURI(
asyncResp->res,
crow::utility::urlFromPieces(