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
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 81af41f..e425cc1 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -46,8 +46,7 @@
const std::string& resName)
{
std::string thisPath = itemPath.filename();
- BMCWEB_LOG_DEBUG << "Filename: " << itemPath.str
- << ", ThisPath: " << thisPath;
+ BMCWEB_LOG_DEBUG("Filename: {}, ThisPath: {}", itemPath.str, thisPath);
if (thisPath.empty())
{
@@ -102,7 +101,7 @@
const dbus::utility::ManagedObjectType& subtree) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "DBUS response error";
+ BMCWEB_LOG_DEBUG("DBUS response error");
return;
}
@@ -117,7 +116,7 @@
}
}
- BMCWEB_LOG_DEBUG << "Parent item not found";
+ BMCWEB_LOG_DEBUG("Parent item not found");
asyncResp->res.result(boost::beast::http::status::not_found);
});
}
@@ -224,7 +223,7 @@
const bool* activeValue = std::get_if<bool>(&value);
if (activeValue == nullptr)
{
- BMCWEB_LOG_DEBUG << "Value Active not found";
+ BMCWEB_LOG_DEBUG("Value Active not found");
return;
}
asyncResp->res.jsonValue["Inserted"] = *activeValue;
@@ -272,7 +271,7 @@
const std::string& service,
const std::string& name)
{
- BMCWEB_LOG_DEBUG << "Get available Virtual Media resources.";
+ BMCWEB_LOG_DEBUG("Get available Virtual Media resources.");
sdbusplus::message::object_path objPath(
"/xyz/openbmc_project/VirtualMedia");
dbus::utility::getManagedObjects(
@@ -282,7 +281,7 @@
const dbus::utility::ManagedObjectType& subtree) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "DBUS response error";
+ BMCWEB_LOG_DEBUG("DBUS response error");
return;
}
nlohmann::json& members = asyncResp->res.jsonValue["Members"];
@@ -344,7 +343,7 @@
const std::string& service, const std::string& name,
const std::string& resName)
{
- BMCWEB_LOG_DEBUG << "Get Virtual Media resource data.";
+ BMCWEB_LOG_DEBUG("Get Virtual Media resource data.");
findAndParseObject(service, resName, asyncResp,
std::bind_front(afterGetVmData, name));
@@ -601,7 +600,7 @@
if (credentials.user().size() + credentials.password().size() + 2 >
secretLimit)
{
- BMCWEB_LOG_ERROR << "Credentials too long to handle";
+ BMCWEB_LOG_ERROR("Credentials too long to handle");
messages::unrecognizedRequestBody(asyncResp->res);
return;
}
@@ -625,7 +624,7 @@
[asyncResp](const boost::system::error_code& ec, std::size_t) {
if (ec)
{
- BMCWEB_LOG_ERROR << "Failed to pass secret: " << ec;
+ BMCWEB_LOG_ERROR("Failed to pass secret: {}", ec);
messages::internalError(asyncResp->res);
}
});
@@ -636,12 +635,12 @@
bool success) {
if (ec)
{
- BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
+ BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
messages::internalError(asyncResp->res);
}
else if (!success)
{
- BMCWEB_LOG_ERROR << "Service responded with error";
+ BMCWEB_LOG_ERROR("Service responded with error");
messages::generalError(asyncResp->res);
}
},
@@ -659,11 +658,11 @@
const std::string& resName,
InsertMediaActionParams& actionParams)
{
- BMCWEB_LOG_DEBUG << "Validation started";
+ BMCWEB_LOG_DEBUG("Validation started");
// required param imageUrl must not be empty
if (!actionParams.imageUrl)
{
- BMCWEB_LOG_ERROR << "Request action parameter Image is empty.";
+ BMCWEB_LOG_ERROR("Request action parameter Image is empty.");
messages::propertyValueFormatError(asyncResp->res, "<empty>", "Image");
@@ -673,8 +672,8 @@
// optional param inserted must be true
if ((actionParams.inserted != std::nullopt) && !*actionParams.inserted)
{
- BMCWEB_LOG_ERROR
- << "Request action optional parameter Inserted must be true.";
+ BMCWEB_LOG_ERROR(
+ "Request action optional parameter Inserted must be true.");
messages::actionParameterNotSupported(asyncResp->res, "Inserted",
"InsertMedia");
@@ -686,8 +685,8 @@
if ((actionParams.transferMethod != std::nullopt) &&
(*actionParams.transferMethod != "Stream"))
{
- BMCWEB_LOG_ERROR << "Request action optional parameter "
- "TransferMethod must be Stream.";
+ BMCWEB_LOG_ERROR("Request action optional parameter "
+ "TransferMethod must be Stream.");
messages::actionParameterNotSupported(asyncResp->res, "TransferMethod",
"InsertMedia");
@@ -711,9 +710,9 @@
// ImageUrl does not contain valid protocol type
if (*uriTransferProtocolType == TransferProtocol::invalid)
{
- BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must "
- "contain specified protocol type from list: "
- "(smb, https).";
+ BMCWEB_LOG_ERROR("Request action parameter ImageUrl must "
+ "contain specified protocol type from list: "
+ "(smb, https).");
messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
@@ -723,9 +722,9 @@
// transferProtocolType should contain value from list
if (*paramTransferProtocolType == TransferProtocol::invalid)
{
- BMCWEB_LOG_ERROR << "Request action parameter TransferProtocolType "
- "must be provided with value from list: "
- "(CIFS, HTTPS).";
+ BMCWEB_LOG_ERROR("Request action parameter TransferProtocolType "
+ "must be provided with value from list: "
+ "(CIFS, HTTPS).");
messages::propertyValueNotInList(asyncResp->res,
*actionParams.transferProtocolType,
@@ -737,9 +736,9 @@
if ((uriTransferProtocolType == std::nullopt) &&
(paramTransferProtocolType == std::nullopt))
{
- BMCWEB_LOG_ERROR << "Request action parameter ImageUrl must "
- "contain specified protocol type or param "
- "TransferProtocolType must be provided.";
+ BMCWEB_LOG_ERROR("Request action parameter ImageUrl must "
+ "contain specified protocol type or param "
+ "TransferProtocolType must be provided.");
messages::resourceAtUriInUnknownFormat(asyncResp->res, *url);
@@ -753,10 +752,10 @@
// check if protocol is the same for URI and param
if (*paramTransferProtocolType != *uriTransferProtocolType)
{
- BMCWEB_LOG_ERROR << "Request action parameter "
- "TransferProtocolType must contain the "
- "same protocol type as protocol type "
- "provided with param imageUrl.";
+ BMCWEB_LOG_ERROR("Request action parameter "
+ "TransferProtocolType must contain the "
+ "same protocol type as protocol type "
+ "provided with param imageUrl.");
messages::actionParameterValueTypeError(
asyncResp->res, *actionParams.transferProtocolType,
@@ -805,7 +804,7 @@
[asyncResp](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
+ BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
messages::internalError(asyncResp->res);
return;
@@ -820,7 +819,7 @@
[asyncResp](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "Bad D-Bus request error: " << ec;
+ BMCWEB_LOG_ERROR("Bad D-Bus request error: {}", ec);
messages::internalError(asyncResp->res);
return;
@@ -869,14 +868,14 @@
const dbus::utility::MapperGetObject& getObjectType) mutable {
if (ec)
{
- BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec;
+ BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
messages::resourceNotFound(asyncResp->res, action, resName);
return;
}
std::string service = getObjectType.begin()->first;
- BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
+ BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
sdbusplus::message::object_path path(
"/xyz/openbmc_project/VirtualMedia");
@@ -888,8 +887,8 @@
if (ec2)
{
// Not possible in proxy mode
- BMCWEB_LOG_DEBUG << "InsertMedia not "
- "allowed in proxy mode";
+ BMCWEB_LOG_DEBUG("InsertMedia not "
+ "allowed in proxy mode");
messages::resourceNotFound(asyncResp->res, action, resName);
return;
@@ -904,7 +903,7 @@
return;
}
}
- BMCWEB_LOG_DEBUG << "Parent item not found";
+ BMCWEB_LOG_DEBUG("Parent item not found");
messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
});
});
@@ -935,13 +934,13 @@
const dbus::utility::MapperGetObject& getObjectType) {
if (ec2)
{
- BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec2;
+ BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec2);
messages::internalError(asyncResp->res);
return;
}
std::string service = getObjectType.begin()->first;
- BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
+ BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
sdbusplus::message::object_path path(
"/xyz/openbmc_project/VirtualMedia");
@@ -952,7 +951,7 @@
const dbus::utility::ManagedObjectType& subtree) {
if (ec)
{
- BMCWEB_LOG_ERROR << "ObjectMapper : No Service found";
+ BMCWEB_LOG_ERROR("ObjectMapper : No Service found");
messages::resourceNotFound(asyncResp->res, action, resName);
return;
}
@@ -967,7 +966,7 @@
return;
}
}
- BMCWEB_LOG_DEBUG << "Parent item not found";
+ BMCWEB_LOG_DEBUG("Parent item not found");
messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
});
});
@@ -1001,13 +1000,13 @@
const dbus::utility::MapperGetObject& getObjectType) {
if (ec)
{
- BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec;
+ BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
messages::internalError(asyncResp->res);
return;
}
std::string service = getObjectType.begin()->first;
- BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
+ BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
getVmResourceList(asyncResp, service, name);
});
@@ -1036,13 +1035,13 @@
const dbus::utility::MapperGetObject& getObjectType) {
if (ec)
{
- BMCWEB_LOG_ERROR << "ObjectMapper::GetObject call failed: " << ec;
+ BMCWEB_LOG_ERROR("ObjectMapper::GetObject call failed: {}", ec);
messages::internalError(asyncResp->res);
return;
}
std::string service = getObjectType.begin()->first;
- BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
+ BMCWEB_LOG_DEBUG("GetObjectType: {}", service);
getVmData(asyncResp, service, name, resName);
});