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/chassis.hpp b/redfish-core/lib/chassis.hpp
index fc89d03..fbab894 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -62,7 +62,7 @@
const std::vector<std::string>& storageList) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "getStorageLink got DBUS response error";
+ BMCWEB_LOG_DEBUG("getStorageLink got DBUS response error");
return;
}
@@ -109,15 +109,15 @@
{
// Service not available, no error, just don't return
// chassis state info
- BMCWEB_LOG_DEBUG << "Service not available " << ec;
+ BMCWEB_LOG_DEBUG("Service not available {}", ec);
return;
}
- BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
+ BMCWEB_LOG_DEBUG("DBUS response error {}", ec);
messages::internalError(asyncResp->res);
return;
}
- BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState;
+ BMCWEB_LOG_DEBUG("Chassis state: {}", chassisState);
// Verify Chassis State
if (chassisState == "xyz.openbmc_project.State.Chassis.PowerState.On")
{
@@ -137,7 +137,7 @@
const std::string& service,
const std::string& objPath)
{
- BMCWEB_LOG_DEBUG << "Get intrusion status by service \n";
+ BMCWEB_LOG_DEBUG("Get intrusion status by service ");
sdbusplus::asio::getProperty<std::string>(
*crow::connections::systemBus, service, objPath,
@@ -148,7 +148,7 @@
{
// do not add err msg in redfish response, because this is not
// mandatory property
- BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n";
+ BMCWEB_LOG_ERROR("DBUS response error {}", ec);
return;
}
@@ -175,7 +175,7 @@
{
// do not add err msg in redfish response, because this is not
// mandatory property
- BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec << "\n";
+ BMCWEB_LOG_INFO("DBUS error: no matched iface {}", ec);
return;
}
// Iterate over all retrieved ObjectPaths.
@@ -220,7 +220,7 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error {}", ec);
messages::internalError(asyncResp->res);
}
return;
@@ -231,7 +231,7 @@
}
if (upstreamChassisPaths.size() > 1)
{
- BMCWEB_LOG_ERROR << chassisId << " is contained by mutliple chassis";
+ BMCWEB_LOG_ERROR("{} is contained by mutliple chassis", chassisId);
messages::internalError(asyncResp->res);
return;
}
@@ -241,8 +241,8 @@
std::string upstreamChassis = upstreamChassisPath.filename();
if (upstreamChassis.empty())
{
- BMCWEB_LOG_WARNING << "Malformed upstream Chassis path "
- << upstreamChassisPath.str << " on " << chassisId;
+ BMCWEB_LOG_WARNING("Malformed upstream Chassis path {} on {}",
+ upstreamChassisPath.str, chassisId);
return;
}
@@ -259,7 +259,7 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error {}", ec);
messages::internalError(asyncResp->res);
}
return;
@@ -280,9 +280,8 @@
std::string downstreamChassis = downstreamChassisPath.filename();
if (downstreamChassis.empty())
{
- BMCWEB_LOG_WARNING << "Malformed downstream Chassis path "
- << downstreamChassisPath.str << " on "
- << chassisId;
+ BMCWEB_LOG_WARNING("Malformed downstream Chassis path {} on {}",
+ downstreamChassisPath.str, chassisId);
continue;
}
nlohmann::json link;
@@ -298,7 +297,7 @@
const std::string& chassisId,
const std::string& chassisPath)
{
- BMCWEB_LOG_DEBUG << "Get chassis connectivity";
+ BMCWEB_LOG_DEBUG("Get chassis connectivity");
dbus::utility::getAssociationEndPoints(
chassisPath + "/contained_by",
@@ -333,7 +332,7 @@
const std::string& property) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error for Location";
+ BMCWEB_LOG_ERROR("DBUS response error for Location");
messages::internalError(asyncResp->res);
return;
}
@@ -354,7 +353,7 @@
const std::string& chassisUUID) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error for UUID";
+ BMCWEB_LOG_ERROR("DBUS response error for UUID");
messages::internalError(asyncResp->res);
return;
}
@@ -382,7 +381,7 @@
const dbus::utility::MapperGetSubTreeResponse& subtree) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -424,7 +423,7 @@
if (connectionNames.empty())
{
- BMCWEB_LOG_ERROR << "Got 0 Connection names";
+ BMCWEB_LOG_ERROR("Got 0 Connection names");
continue;
}
@@ -484,8 +483,8 @@
const std::string& property) {
if (ec2)
{
- BMCWEB_LOG_ERROR
- << "DBus response error for AssetTag: " << ec2;
+ BMCWEB_LOG_ERROR(
+ "DBus response error for AssetTag: {}", ec2);
messages::internalError(asyncResp->res);
return;
}
@@ -502,9 +501,9 @@
const bool property) {
if (ec2)
{
- BMCWEB_LOG_ERROR
- << "DBus response error for HotPluggable: "
- << ec2;
+ BMCWEB_LOG_ERROR(
+ "DBus response error for HotPluggable: {}",
+ ec2);
messages::internalError(asyncResp->res);
return;
}
@@ -693,7 +692,7 @@
const dbus::utility::MapperGetSubTreeResponse& subtree) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -716,7 +715,7 @@
if (connectionNames.empty())
{
- BMCWEB_LOG_ERROR << "Got 0 Connection names";
+ BMCWEB_LOG_ERROR("Got 0 Connection names");
continue;
}
@@ -793,7 +792,7 @@
{
if (eMsg.get_error() == nullptr)
{
- BMCWEB_LOG_ERROR << "D-Bus response error: " << ec;
+ BMCWEB_LOG_ERROR("D-Bus response error: {}", ec);
messages::internalError(res);
return;
}
@@ -804,13 +803,13 @@
if (errorMessage ==
std::string_view("xyz.openbmc_project.State.Chassis.Error.BMCNotReady"))
{
- BMCWEB_LOG_DEBUG << "BMC not ready, operation not allowed right now";
+ BMCWEB_LOG_DEBUG("BMC not ready, operation not allowed right now");
messages::serviceTemporarilyUnavailable(res, "10");
return;
}
- BMCWEB_LOG_ERROR << "Chassis Power Cycle fail " << ec
- << " sdbusplus:" << errorMessage;
+ BMCWEB_LOG_ERROR("Chassis Power Cycle fail {} sdbusplus:{}", ec,
+ errorMessage);
messages::internalError(res);
}
@@ -828,7 +827,7 @@
const dbus::utility::MapperGetSubTreePathsResponse& chassisList) {
if (ec)
{
- BMCWEB_LOG_ERROR << "[mapper] Bad D-Bus request error: " << ec;
+ BMCWEB_LOG_ERROR("[mapper] Bad D-Bus request error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -877,7 +876,7 @@
{
return;
}
- BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
+ BMCWEB_LOG_DEBUG("Post Chassis Reset.");
std::string resetType;
@@ -888,8 +887,7 @@
if (resetType != "PowerCycle")
{
- BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
- << resetType;
+ BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType);
messages::actionParameterNotSupported(asyncResp->res, resetType,
"ResetType");