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/power_supply.hpp b/redfish-core/lib/power_supply.hpp
index 09f731b..0035b11 100644
--- a/redfish-core/lib/power_supply.hpp
+++ b/redfish-core/lib/power_supply.hpp
@@ -82,7 +82,7 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error" << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error{}", ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -171,9 +171,9 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR
- << "DBUS response error for getAssociatedSubTreePaths"
- << ec.value();
+ BMCWEB_LOG_ERROR(
+ "DBUS response error for getAssociatedSubTreePaths{}",
+ ec.value());
messages::internalError(asyncResp->res);
return;
}
@@ -193,7 +193,7 @@
if (!subtreePaths.empty())
{
- BMCWEB_LOG_WARNING << "Power supply not found: " << powerSupplyId;
+ BMCWEB_LOG_WARNING("Power supply not found: {}", powerSupplyId);
messages::resourceNotFound(asyncResp->res, "PowerSupplies",
powerSupplyId);
return;
@@ -213,8 +213,8 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error for State "
- << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error for State {}",
+ ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -239,8 +239,8 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error for Health "
- << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error for Health {}",
+ ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -266,8 +266,8 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error for Asset "
- << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error for Asset {}",
+ ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -331,8 +331,8 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error for FirmwareVersion "
- << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error for FirmwareVersion {}",
+ ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -354,8 +354,8 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error for Location "
- << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error for Location {}",
+ ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -373,8 +373,8 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error for DeratingFactor "
- << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error for DeratingFactor {}",
+ ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -402,8 +402,8 @@
{
if (ec.value() != EBADR)
{
- BMCWEB_LOG_ERROR << "DBUS response error for EfficiencyPercent "
- << ec.value();
+ BMCWEB_LOG_ERROR("DBUS response error for EfficiencyPercent {}",
+ ec.value());
messages::internalError(asyncResp->res);
}
return;
@@ -411,15 +411,15 @@
if (subtree.empty())
{
- BMCWEB_LOG_DEBUG << "Can't find Power Supply Attributes!";
+ BMCWEB_LOG_DEBUG("Can't find Power Supply Attributes!");
return;
}
if (subtree.size() != 1)
{
- BMCWEB_LOG_ERROR
- << "Unexpected number of paths returned by getSubTree: "
- << subtree.size();
+ BMCWEB_LOG_ERROR(
+ "Unexpected number of paths returned by getSubTree: {}",
+ subtree.size());
messages::internalError(asyncResp->res);
return;
}