summaryrefslogtreecommitdiff
path: root/include/hostname_monitor.hpp
diff options
context:
space:
mode:
authorEd Tanous <ed@tanous.net>2023-07-18 03:06:25 +0300
committerEd Tanous <ed@tanous.net>2023-07-20 01:38:41 +0300
commit62598e31d0988d589506d5091bd38f72d61faf5e (patch)
treee3e548632da934083c21cc1262f8b9d8f255f2a9 /include/hostname_monitor.hpp
parent609ba4c9ffb9c6b83861ff557108c89007ca369a (diff)
downloadbmcweb-62598e31d0988d589506d5091bd38f72d61faf5e.tar.xz
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
Diffstat (limited to 'include/hostname_monitor.hpp')
-rw-r--r--include/hostname_monitor.hpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp
index fd49b02cf4..f1a0d3d2c1 100644
--- a/include/hostname_monitor.hpp
+++ b/include/hostname_monitor.hpp
@@ -22,12 +22,12 @@ inline void installCertificate(const std::filesystem::path& certPath)
[certPath](const boost::system::error_code& ec) {
if (ec)
{
- BMCWEB_LOG_ERROR << "Replace Certificate Fail..";
+ BMCWEB_LOG_ERROR("Replace Certificate Fail..");
return;
}
- BMCWEB_LOG_INFO << "Replace HTTPs Certificate Success, "
- "remove temporary certificate file..";
+ BMCWEB_LOG_INFO("Replace HTTPs Certificate Success, "
+ "remove temporary certificate file..");
remove(certPath.c_str());
},
"xyz.openbmc_project.Certs.Manager.Server.Https",
@@ -40,7 +40,7 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */,
{
if (retError == nullptr || (sd_bus_error_is_set(retError) != 0))
{
- BMCWEB_LOG_ERROR << "Got sdbus error on match";
+ BMCWEB_LOG_ERROR("Got sdbus error on match");
return 0;
}
@@ -62,13 +62,13 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */,
return 0;
}
- BMCWEB_LOG_DEBUG << "Read hostname from signal: " << *hostname;
+ BMCWEB_LOG_DEBUG("Read hostname from signal: {}", *hostname);
const std::string certFile = "/etc/ssl/certs/https/server.pem";
X509* cert = ensuressl::loadCert(certFile);
if (cert == nullptr)
{
- BMCWEB_LOG_ERROR << "Failed to read cert";
+ BMCWEB_LOG_ERROR("Failed to read cert");
return 0;
}
@@ -80,7 +80,7 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */,
cnBuffer.size());
if (cnLength == -1)
{
- BMCWEB_LOG_ERROR << "Failed to read NID_commonName";
+ BMCWEB_LOG_ERROR("Failed to read NID_commonName");
X509_free(cert);
return 0;
}
@@ -90,16 +90,16 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */,
EVP_PKEY* pPubKey = X509_get_pubkey(cert);
if (pPubKey == nullptr)
{
- BMCWEB_LOG_ERROR << "Failed to get public key";
+ BMCWEB_LOG_ERROR("Failed to get public key");
X509_free(cert);
return 0;
}
int isSelfSigned = X509_verify(cert, pPubKey);
EVP_PKEY_free(pPubKey);
- BMCWEB_LOG_DEBUG << "Current HTTPs Certificate Subject CN: " << cnValue
- << ", New HostName: " << *hostname
- << ", isSelfSigned: " << isSelfSigned;
+ BMCWEB_LOG_DEBUG(
+ "Current HTTPs Certificate Subject CN: {}, New HostName: {}, isSelfSigned: {}",
+ cnValue, *hostname, isSelfSigned);
ASN1_IA5STRING* asn1 = static_cast<ASN1_IA5STRING*>(
X509_get_ext_d2i(cert, NID_netscape_comment, nullptr, nullptr));
@@ -108,13 +108,14 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */,
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
std::string_view comment(reinterpret_cast<const char*>(asn1->data),
static_cast<size_t>(asn1->length));
- BMCWEB_LOG_DEBUG << "x509Comment: " << comment;
+ BMCWEB_LOG_DEBUG("x509Comment: {}", comment);
if (ensuressl::x509Comment == comment && isSelfSigned == 1 &&
cnValue != *hostname)
{
- BMCWEB_LOG_INFO << "Ready to generate new HTTPs "
- << "certificate with subject cn: " << *hostname;
+ BMCWEB_LOG_INFO(
+ "Ready to generate new HTTPs certificate with subject cn: {}",
+ *hostname);
ensuressl::generateSslCertificate("/tmp/hostname_cert.tmp",
*hostname);
@@ -128,7 +129,7 @@ inline int onPropertyUpdate(sd_bus_message* m, void* /* userdata */,
inline void registerHostnameSignal()
{
- BMCWEB_LOG_INFO << "Register HostName PropertiesChanged Signal";
+ BMCWEB_LOG_INFO("Register HostName PropertiesChanged Signal");
std::string propertiesMatchString =
("type='signal',"
"interface='org.freedesktop.DBus.Properties',"