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/account_service.hpp b/redfish-core/lib/account_service.hpp
index cb469bd..173de73 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -211,8 +211,8 @@
// Both Redfish and WebUI Account Types are needed to PATCH
if (redfishType ^ webUIType)
{
- BMCWEB_LOG_ERROR
- << "Missing Redfish or WebUI Account Type to set redfish User Group";
+ BMCWEB_LOG_ERROR(
+ "Missing Redfish or WebUI Account Type to set redfish User Group");
messages::strictAccountTypes(res, "AccountTypes");
return false;
}
@@ -243,8 +243,8 @@
(accountTypes.cend() ==
std::find(accountTypes.cbegin(), accountTypes.cend(), "Redfish")))
{
- BMCWEB_LOG_ERROR
- << "User disabling OWN Redfish Account Type is not allowed";
+ BMCWEB_LOG_ERROR(
+ "User disabling OWN Redfish Account Type is not allowed");
messages::strictAccountTypes(asyncResp->res, "AccountTypes");
return;
}
@@ -264,7 +264,7 @@
updatedUserGroups, [asyncResp](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+ BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -342,8 +342,7 @@
roleMapArray = nlohmann::json::array();
for (const auto& obj : confData.groupRoleList)
{
- BMCWEB_LOG_DEBUG << "Pushing the data groupName="
- << obj.second.groupName << "\n";
+ BMCWEB_LOG_DEBUG("Pushing the data groupName={}", obj.second.groupName);
nlohmann::json::object_t remoteGroup;
remoteGroup["RemoteGroup"] = obj.second.groupName;
@@ -376,7 +375,7 @@
index](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -388,7 +387,7 @@
}
else
{
- BMCWEB_LOG_ERROR << "Can't delete the object";
+ BMCWEB_LOG_ERROR("Can't delete the object");
messages::propertyValueTypeError(asyncResp->res, thisJson,
"RemoteRoleMapping/" +
std::to_string(index));
@@ -419,7 +418,7 @@
// Update existing RoleMapping Object
if (index < roleMapObjData.size())
{
- BMCWEB_LOG_DEBUG << "Update Role Map Object";
+ BMCWEB_LOG_DEBUG("Update Role Map Object");
// If "RemoteGroup" info is provided
if (remoteGroup)
{
@@ -439,8 +438,8 @@
std::string_view(
"xyz.openbmc_project.Common.Error.InvalidArgument")))
{
- BMCWEB_LOG_WARNING << "DBUS response error: "
- << ec;
+ BMCWEB_LOG_WARNING("DBUS response error: {}",
+ ec);
messages::propertyValueIncorrect(asyncResp->res,
"RemoteGroup",
*remoteGroup);
@@ -474,8 +473,8 @@
std::string_view(
"xyz.openbmc_project.Common.Error.InvalidArgument")))
{
- BMCWEB_LOG_WARNING << "DBUS response error: "
- << ec;
+ BMCWEB_LOG_WARNING("DBUS response error: {}",
+ ec);
messages::propertyValueIncorrect(
asyncResp->res, "LocalRole", *localRole);
return;
@@ -492,8 +491,8 @@
// Create a new RoleMapping Object.
else
{
- BMCWEB_LOG_DEBUG
- << "setRoleMappingProperties: Creating new Object";
+ BMCWEB_LOG_DEBUG(
+ "setRoleMappingProperties: Creating new Object");
std::string pathString = "RemoteRoleMapping/" +
std::to_string(index);
@@ -520,15 +519,15 @@
dbusObjectPath = ldapConfigObjectName;
}
- BMCWEB_LOG_DEBUG << "Remote Group=" << *remoteGroup
- << ",LocalRole=" << *localRole;
+ BMCWEB_LOG_DEBUG("Remote Group={},LocalRole={}", *remoteGroup,
+ *localRole);
crow::connections::systemBus->async_method_call(
[asyncResp, serverType, localRole,
remoteGroup](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -565,8 +564,8 @@
const dbus::utility::MapperGetObject& resp) {
if (ec || resp.empty())
{
- BMCWEB_LOG_ERROR
- << "DBUS response error during getting of service name: " << ec;
+ BMCWEB_LOG_ERROR(
+ "DBUS response error during getting of service name: {}", ec);
LDAPConfigData empty{};
callback(false, empty, ldapType);
return;
@@ -582,7 +581,7 @@
if (ec2)
{
callback(false, confData, ldapType);
- BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec2;
+ BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec2);
return;
}
@@ -603,8 +602,8 @@
}
else
{
- BMCWEB_LOG_ERROR << "Can't get the DbusType for the given type="
- << ldapType;
+ BMCWEB_LOG_ERROR("Can't get the DbusType for the given type={}",
+ ldapType);
callback(false, confData, ldapType);
return;
}
@@ -808,8 +807,8 @@
std::string_view(
"xyz.openbmc_project.Common.Error.InvalidArgument")))
{
- BMCWEB_LOG_WARNING
- << "Error Occurred in updating the service address";
+ BMCWEB_LOG_WARNING(
+ "Error Occurred in updating the service address");
messages::propertyValueIncorrect(asyncResp->res,
"ServiceAddresses",
serviceAddressList.front());
@@ -827,7 +826,7 @@
messages::propertyValueModified(asyncResp->res, "ServiceAddresses",
serviceAddressList.front());
}
- BMCWEB_LOG_DEBUG << "Updated the service address";
+ BMCWEB_LOG_DEBUG("Updated the service address");
});
}
/**
@@ -852,13 +851,13 @@
const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "Error occurred in updating the username";
+ BMCWEB_LOG_DEBUG("Error occurred in updating the username");
messages::internalError(asyncResp->res);
return;
}
asyncResp->res.jsonValue[ldapServerElementName]["Authentication"]
["Username"] = username;
- BMCWEB_LOG_DEBUG << "Updated the username";
+ BMCWEB_LOG_DEBUG("Updated the username");
});
}
@@ -883,13 +882,13 @@
const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "Error occurred in updating the password";
+ BMCWEB_LOG_DEBUG("Error occurred in updating the password");
messages::internalError(asyncResp->res);
return;
}
asyncResp->res.jsonValue[ldapServerElementName]["Authentication"]
["Password"] = "";
- BMCWEB_LOG_DEBUG << "Updated the password";
+ BMCWEB_LOG_DEBUG("Updated the password");
});
}
@@ -916,7 +915,7 @@
const sdbusplus::message_t& msg) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "Error Occurred in Updating the base DN";
+ BMCWEB_LOG_DEBUG("Error Occurred in Updating the base DN");
const sd_bus_error* dbusError = msg.get_error();
if ((dbusError != nullptr) &&
(dbusError->name ==
@@ -941,7 +940,7 @@
messages::propertyValueModified(
asyncResp->res, "BaseDistinguishedNames", baseDNList.front());
}
- BMCWEB_LOG_DEBUG << "Updated the base DN";
+ BMCWEB_LOG_DEBUG("Updated the base DN");
});
}
/**
@@ -966,8 +965,8 @@
ldapServerElementName](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "Error Occurred in Updating the "
- "username attribute";
+ BMCWEB_LOG_DEBUG("Error Occurred in Updating the "
+ "username attribute");
messages::internalError(asyncResp->res);
return;
}
@@ -975,7 +974,7 @@
auto& searchSettingsJson =
serverTypeJson["LDAPService"]["SearchSettings"];
searchSettingsJson["UsernameAttribute"] = userNameAttribute;
- BMCWEB_LOG_DEBUG << "Updated the user name attr.";
+ BMCWEB_LOG_DEBUG("Updated the user name attr.");
});
}
/**
@@ -1000,8 +999,8 @@
ldapServerElementName](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "Error Occurred in Updating the "
- "groupname attribute";
+ BMCWEB_LOG_DEBUG("Error Occurred in Updating the "
+ "groupname attribute");
messages::internalError(asyncResp->res);
return;
}
@@ -1009,7 +1008,7 @@
auto& searchSettingsJson =
serverTypeJson["LDAPService"]["SearchSettings"];
searchSettingsJson["GroupsAttribute"] = groupsAttribute;
- BMCWEB_LOG_DEBUG << "Updated the groupname attr";
+ BMCWEB_LOG_DEBUG("Updated the groupname attr");
});
}
/**
@@ -1033,13 +1032,13 @@
ldapServerElementName](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "Error Occurred in Updating the service enable";
+ BMCWEB_LOG_DEBUG("Error Occurred in Updating the service enable");
messages::internalError(asyncResp->res);
return;
}
asyncResp->res.jsonValue[ldapServerElementName]["ServiceEnabled"] =
serviceEnabled;
- BMCWEB_LOG_DEBUG << "Updated Service enable = " << serviceEnabled;
+ BMCWEB_LOG_DEBUG("Updated Service enable = {}", serviceEnabled);
});
}
@@ -1057,7 +1056,7 @@
"Cookie", cookie, "SessionToken", sessionToken,
"XToken", xToken, "TLS", tls))
{
- BMCWEB_LOG_ERROR << "Cannot read values from AuthMethod tag";
+ BMCWEB_LOG_ERROR("Cannot read values from AuthMethod tag");
return;
}
@@ -1334,7 +1333,7 @@
// If password is invalid
messages::propertyValueFormatError(asyncResp->res,
*password, "Password");
- BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
+ BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
}
else if (retval != PAM_SUCCESS)
{
@@ -1356,7 +1355,7 @@
*enabled, [asyncResp](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+ BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -1381,7 +1380,7 @@
priv, [asyncResp](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+ BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -1409,7 +1408,7 @@
[asyncResp](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec;
+ BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -1506,8 +1505,8 @@
return;
}
- BMCWEB_LOG_DEBUG << "Got " << propertiesList.size()
- << "properties for AccountService";
+ BMCWEB_LOG_DEBUG("Got {}properties for AccountService",
+ propertiesList.size());
const uint8_t* minPasswordLength = nullptr;
const uint32_t* accountUnlockTimeout = nullptr;
@@ -1737,7 +1736,7 @@
if (user.empty())
{
messages::internalError(asyncResp->res);
- BMCWEB_LOG_ERROR << "Invalid firmware ID";
+ BMCWEB_LOG_ERROR("Invalid firmware ID");
return;
}
@@ -1795,7 +1794,7 @@
"xyz.openbmc_project.User.Manager", userPath,
"xyz.openbmc_project.Object.Delete", "Delete");
- BMCWEB_LOG_ERROR << "pamUpdatePassword Failed";
+ BMCWEB_LOG_ERROR("pamUpdatePassword Failed");
return;
}
@@ -1854,8 +1853,8 @@
{
if (!accountTypeUserGroups.empty())
{
- BMCWEB_LOG_ERROR
- << "Only administrator can get HostConsole access";
+ BMCWEB_LOG_ERROR(
+ "Only administrator can get HostConsole access");
asyncResp->res.result(boost::beast::http::status::bad_request);
return;
}
@@ -1921,7 +1920,7 @@
const std::vector<std::string>& allGroupsList) {
if (ec)
{
- BMCWEB_LOG_DEBUG << "ERROR with async_method_call";
+ BMCWEB_LOG_DEBUG("ERROR with async_method_call");
messages::internalError(asyncResp->res);
return;
}
@@ -1988,7 +1987,7 @@
if (!effectiveUserPrivileges.isSupersetOf(
requiredPermissionsToChangeNonSelf))
{
- BMCWEB_LOG_DEBUG << "GET Account denied access";
+ BMCWEB_LOG_DEBUG("GET Account denied access");
messages::insufficientPrivilege(asyncResp->res);
return;
}
@@ -2039,7 +2038,7 @@
std::get_if<bool>(&property.second);
if (userEnabled == nullptr)
{
- BMCWEB_LOG_ERROR << "UserEnabled wasn't a bool";
+ BMCWEB_LOG_ERROR("UserEnabled wasn't a bool");
messages::internalError(asyncResp->res);
return;
}
@@ -2051,9 +2050,9 @@
std::get_if<bool>(&property.second);
if (userLocked == nullptr)
{
- BMCWEB_LOG_ERROR << "UserLockedForF"
- "ailedAttempt "
- "wasn't a bool";
+ BMCWEB_LOG_ERROR("UserLockedForF"
+ "ailedAttempt "
+ "wasn't a bool");
messages::internalError(asyncResp->res);
return;
}
@@ -2068,15 +2067,15 @@
std::get_if<std::string>(&property.second);
if (userPrivPtr == nullptr)
{
- BMCWEB_LOG_ERROR << "UserPrivilege wasn't a "
- "string";
+ BMCWEB_LOG_ERROR("UserPrivilege wasn't a "
+ "string");
messages::internalError(asyncResp->res);
return;
}
std::string role = getRoleIdFromPrivilege(*userPrivPtr);
if (role.empty())
{
- BMCWEB_LOG_ERROR << "Invalid user role";
+ BMCWEB_LOG_ERROR("Invalid user role");
messages::internalError(asyncResp->res);
return;
}
@@ -2093,8 +2092,8 @@
std::get_if<bool>(&property.second);
if (userPasswordExpired == nullptr)
{
- BMCWEB_LOG_ERROR
- << "UserPasswordExpired wasn't a bool";
+ BMCWEB_LOG_ERROR(
+ "UserPasswordExpired wasn't a bool");
messages::internalError(asyncResp->res);
return;
}
@@ -2108,14 +2107,14 @@
&property.second);
if (userGroups == nullptr)
{
- BMCWEB_LOG_ERROR
- << "userGroups wasn't a string vector";
+ BMCWEB_LOG_ERROR(
+ "userGroups wasn't a string vector");
messages::internalError(asyncResp->res);
return;
}
if (!translateUserGroup(*userGroups, asyncResp->res))
{
- BMCWEB_LOG_ERROR << "userGroups mapping failed";
+ BMCWEB_LOG_ERROR("userGroups mapping failed");
messages::internalError(asyncResp->res);
return;
}