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/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 62704c9..0073bc9 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -70,7 +70,7 @@
certificate, "CertificateType",
certificateType))
{
- BMCWEB_LOG_ERROR << "Required parameters are missing";
+ BMCWEB_LOG_ERROR("Required parameters are missing");
messages::internalError(asyncResp->res);
return {};
}
@@ -111,22 +111,22 @@
std::ofstream::trunc);
out << certString;
out.close();
- BMCWEB_LOG_DEBUG << "Creating certificate file"
- << certificateFile.string();
+ BMCWEB_LOG_DEBUG("Creating certificate file{}",
+ certificateFile.string());
}
}
~CertificateFile()
{
if (std::filesystem::exists(certDirectory))
{
- BMCWEB_LOG_DEBUG << "Removing certificate file"
- << certificateFile.string();
+ 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.string();
+ BMCWEB_LOG_ERROR("Failed to remove temp directory{}",
+ certDirectory.string());
}
}
}
@@ -228,7 +228,7 @@
const dbus::utility::MapperGetSubTreePathsResponse& certPaths) {
if (ec)
{
- BMCWEB_LOG_ERROR << "Certificate collection query failed: " << ec;
+ BMCWEB_LOG_ERROR("Certificate collection query failed: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -241,7 +241,7 @@
std::string certId = objPath.filename();
if (certId.empty())
{
- BMCWEB_LOG_ERROR << "Invalid certificate objPath " << certPath;
+ BMCWEB_LOG_ERROR("Invalid certificate objPath {}", certPath);
continue;
}
@@ -294,8 +294,8 @@
const std::string& certId, const boost::urls::url& certURL,
const std::string& name)
{
- BMCWEB_LOG_DEBUG << "getCertificateProperties Path=" << objectPath
- << " certId=" << certId << " certURl=" << certURL;
+ BMCWEB_LOG_DEBUG("getCertificateProperties Path={} certId={} certURl={}",
+ objectPath, certId, certURL);
sdbusplus::asio::getAllProperties(
*crow::connections::systemBus, service, objectPath, certs::certPropIntf,
[asyncResp, certURL, certId,
@@ -303,7 +303,7 @@
const dbus::utility::DBusPropertiesMap& properties) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
messages::resourceNotFound(asyncResp->res, "Certificate", certId);
return;
}
@@ -389,7 +389,7 @@
messages::resourceNotFound(asyncResp->res, "Certificate", id);
return;
}
- BMCWEB_LOG_INFO << "Certificate deleted";
+ BMCWEB_LOG_INFO("Certificate deleted");
asyncResp->res.result(boost::beast::http::status::no_content);
},
service, objectPath, certs::objDeleteIntf, "Delete");
@@ -479,7 +479,7 @@
certificateUri, "CertificateType",
certificateType))
{
- BMCWEB_LOG_ERROR << "Required parameters are missing";
+ BMCWEB_LOG_ERROR("Required parameters are missing");
return;
}
@@ -503,7 +503,7 @@
"CertificateUri");
return;
}
- BMCWEB_LOG_INFO << "Certificate URI to replace: " << certURI;
+ BMCWEB_LOG_INFO("Certificate URI to replace: {}", certURI);
boost::urls::result<boost::urls::url_view> parsedUrl =
boost::urls::parse_relative_ref(certURI);
@@ -559,7 +559,7 @@
name](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
if (ec.value() ==
boost::system::linux_error::bad_request_descriptor)
{
@@ -570,8 +570,8 @@
return;
}
getCertificateProperties(asyncResp, objectPath, service, id, url, name);
- BMCWEB_LOG_DEBUG << "HTTPS certificate install file="
- << certFile->getCertFilePath();
+ BMCWEB_LOG_DEBUG("HTTPS certificate install file={}",
+ certFile->getCertFilePath());
},
service, objectPath, certs::certReplaceIntf, "Replace",
certFile->getCertFilePath());
@@ -594,21 +594,20 @@
const std::string& certObjPath,
const std::string& csrObjPath)
{
- BMCWEB_LOG_DEBUG << "getCSR CertObjectPath" << certObjPath
- << " CSRObjectPath=" << csrObjPath
- << " service=" << service;
+ BMCWEB_LOG_DEBUG("getCSR CertObjectPath{} CSRObjectPath={} service={}",
+ certObjPath, csrObjPath, service);
crow::connections::systemBus->async_method_call(
[asyncResp, certURI](const boost::system::error_code& ec,
const std::string& csr) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
if (csr.empty())
{
- BMCWEB_LOG_ERROR << "CSR read is empty";
+ BMCWEB_LOG_ERROR("CSR read is empty");
messages::internalError(asyncResp->res);
return;
}
@@ -793,16 +792,16 @@
// before completion.
if (ec != boost::asio::error::operation_aborted)
{
- BMCWEB_LOG_ERROR << "Async_wait failed " << ec;
+ BMCWEB_LOG_ERROR("Async_wait failed {}", ec);
}
return;
}
- BMCWEB_LOG_ERROR << "Timed out waiting for Generating CSR";
+ BMCWEB_LOG_ERROR("Timed out waiting for Generating CSR");
messages::internalError(asyncResp->res);
});
// create a matcher to wait on CSR object
- BMCWEB_LOG_DEBUG << "create matcher with path " << objectPath;
+ BMCWEB_LOG_DEBUG("create matcher with path {}", objectPath);
std::string match("type='signal',"
"interface='org.freedesktop.DBus.ObjectManager',"
"path='" +
@@ -815,7 +814,7 @@
timeout.cancel();
if (m.is_method_error())
{
- BMCWEB_LOG_ERROR << "Dbus method error!!!";
+ BMCWEB_LOG_ERROR("Dbus method error!!!");
messages::internalError(asyncResp->res);
return;
}
@@ -824,7 +823,7 @@
sdbusplus::message::object_path csrObjectPath;
m.read(csrObjectPath, interfacesProperties);
- BMCWEB_LOG_DEBUG << "CSR object added" << csrObjectPath.str;
+ BMCWEB_LOG_DEBUG("CSR object added{}", csrObjectPath.str);
for (const auto& interface : interfacesProperties)
{
if (interface.first == "xyz.openbmc_project.Certs.CSR")
@@ -839,7 +838,7 @@
[asyncResp](const boost::system::error_code& ec, const std::string&) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec.message();
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec.message());
messages::internalError(asyncResp->res);
return;
}
@@ -909,7 +908,7 @@
{
return;
}
- BMCWEB_LOG_DEBUG << "HTTPSCertificateCollection::doPost";
+ BMCWEB_LOG_DEBUG("HTTPSCertificateCollection::doPost");
asyncResp->res.jsonValue["Name"] = "HTTPS Certificate";
asyncResp->res.jsonValue["Description"] = "HTTPS Certificate";
@@ -918,7 +917,7 @@
if (certFileBody.empty())
{
- BMCWEB_LOG_ERROR << "Cannot get certificate from request body.";
+ BMCWEB_LOG_ERROR("Cannot get certificate from request body.");
messages::unrecognizedRequestBody(asyncResp->res);
return;
}
@@ -931,7 +930,7 @@
const std::string& objectPath) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -943,8 +942,8 @@
certId);
getCertificateProperties(asyncResp, objectPath, certs::httpsServiceName,
certId, certURL, "HTTPS Certificate");
- BMCWEB_LOG_DEBUG << "HTTPS certificate install file="
- << certFile->getCertFilePath();
+ BMCWEB_LOG_DEBUG("HTTPS certificate install file={}",
+ certFile->getCertFilePath());
},
certs::httpsServiceName, certs::httpsObjectPath, certs::certInstallIntf,
"Install", certFile->getCertFilePath());
@@ -959,7 +958,7 @@
return;
}
- BMCWEB_LOG_DEBUG << "HTTPS Certificate ID=" << id;
+ BMCWEB_LOG_DEBUG("HTTPS Certificate ID={}", id);
const boost::urls::url certURL = boost::urls::format(
"/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/{}", id);
std::string objPath =
@@ -1024,7 +1023,7 @@
if (certFileBody.empty())
{
- BMCWEB_LOG_ERROR << "Cannot get certificate from request body.";
+ BMCWEB_LOG_ERROR("Cannot get certificate from request body.");
messages::unrecognizedRequestBody(asyncResp->res);
return;
}
@@ -1037,7 +1036,7 @@
const std::string& objectPath) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -1048,8 +1047,8 @@
"/redfish/v1/AccountService/LDAP/Certificates/{}", certId);
getCertificateProperties(asyncResp, objectPath, certs::ldapServiceName,
certId, certURL, "LDAP Certificate");
- BMCWEB_LOG_DEBUG << "LDAP certificate install file="
- << certFile->getCertFilePath();
+ BMCWEB_LOG_DEBUG("LDAP certificate install file={}",
+ certFile->getCertFilePath());
},
certs::ldapServiceName, certs::ldapObjectPath, certs::certInstallIntf,
"Install", certFile->getCertFilePath());
@@ -1064,7 +1063,7 @@
return;
}
- BMCWEB_LOG_DEBUG << "LDAP Certificate ID=" << id;
+ BMCWEB_LOG_DEBUG("LDAP Certificate ID={}", id);
const boost::urls::url certURL = boost::urls::format(
"/redfish/v1/AccountService/LDAP/Certificates/{}", id);
std::string objPath =
@@ -1082,7 +1081,7 @@
return;
}
- BMCWEB_LOG_DEBUG << "Delete LDAP Certificate ID=" << id;
+ BMCWEB_LOG_DEBUG("Delete LDAP Certificate ID={}", id);
std::string objPath =
sdbusplus::message::object_path(certs::ldapObjectPath) / id;
@@ -1146,7 +1145,7 @@
if (certFileBody.empty())
{
- BMCWEB_LOG_ERROR << "Cannot get certificate from request body.";
+ BMCWEB_LOG_ERROR("Cannot get certificate from request body.");
messages::unrecognizedRequestBody(asyncResp->res);
return;
}
@@ -1158,7 +1157,7 @@
const std::string& objectPath) {
if (ec)
{
- BMCWEB_LOG_ERROR << "DBUS response error: " << ec;
+ BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
messages::internalError(asyncResp->res);
return;
}
@@ -1170,8 +1169,8 @@
getCertificateProperties(asyncResp, objectPath,
certs::authorityServiceName, certId, certURL,
"TrustStore Certificate");
- BMCWEB_LOG_DEBUG << "TrustStore certificate install file="
- << certFile->getCertFilePath();
+ BMCWEB_LOG_DEBUG("TrustStore certificate install file={}",
+ certFile->getCertFilePath());
},
certs::authorityServiceName, certs::authorityObjectPath,
certs::certInstallIntf, "Install", certFile->getCertFilePath());
@@ -1186,7 +1185,7 @@
return;
}
- BMCWEB_LOG_DEBUG << "Truststore Certificate ID=" << id;
+ BMCWEB_LOG_DEBUG("Truststore Certificate ID={}", id);
const boost::urls::url certURL = boost::urls::format(
"/redfish/v1/Managers/bmc/Truststore/Certificates/{}", id);
std::string objPath =
@@ -1204,7 +1203,7 @@
return;
}
- BMCWEB_LOG_DEBUG << "Delete TrustStore Certificate ID=" << id;
+ BMCWEB_LOG_DEBUG("Delete TrustStore Certificate ID={}", id);
std::string objPath =
sdbusplus::message::object_path(certs::authorityObjectPath) / id;