diff options
author | Ed Tanous <ed@tanous.net> | 2023-07-18 03:06:25 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-07-20 01:38:41 +0300 |
commit | 62598e31d0988d589506d5091bd38f72d61faf5e (patch) | |
tree | e3e548632da934083c21cc1262f8b9d8f255f2a9 /include/persistent_data.hpp | |
parent | 609ba4c9ffb9c6b83861ff557108c89007ca369a (diff) | |
download | bmcweb-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/persistent_data.hpp')
-rw-r--r-- | include/persistent_data.hpp | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/include/persistent_data.hpp b/include/persistent_data.hpp index a08ca7e086..5079a8c151 100644 --- a/include/persistent_data.hpp +++ b/include/persistent_data.hpp @@ -57,8 +57,7 @@ class ConfigFile auto data = nlohmann::json::parse(persistentFile, nullptr, false); if (data.is_discarded()) { - BMCWEB_LOG_ERROR - << "Error parsing persistent data in json file."; + BMCWEB_LOG_ERROR("Error parsing persistent data in json file."); } else { @@ -72,7 +71,7 @@ class ConfigFile item.value().get_ptr<const uint64_t*>(); if (uintPtr == nullptr) { - BMCWEB_LOG_ERROR << "Failed to read revision flag"; + BMCWEB_LOG_ERROR("Failed to read revision flag"); } else { @@ -103,15 +102,15 @@ class ConfigFile if (newSession == nullptr) { - BMCWEB_LOG_ERROR << "Problem reading session " - "from persistent store"; + BMCWEB_LOG_ERROR("Problem reading session " + "from persistent store"); continue; } - BMCWEB_LOG_DEBUG - << "Restored session: " << newSession->csrfToken - << " " << newSession->uniqueId << " " - << newSession->sessionToken; + BMCWEB_LOG_DEBUG("Restored session: {} {} {}", + newSession->csrfToken, + newSession->uniqueId, + newSession->sessionToken); SessionStore::getInstance().authTokens.emplace( newSession->sessionToken, newSession); } @@ -122,13 +121,13 @@ class ConfigFile item.value().get_ptr<int64_t*>(); if (jTimeout == nullptr) { - BMCWEB_LOG_DEBUG - << "Problem reading session timeout value"; + BMCWEB_LOG_DEBUG( + "Problem reading session timeout value"); continue; } std::chrono::seconds sessionTimeoutInseconds(*jTimeout); - BMCWEB_LOG_DEBUG << "Restored Session Timeout: " - << sessionTimeoutInseconds.count(); + BMCWEB_LOG_DEBUG("Restored Session Timeout: {}", + sessionTimeoutInseconds.count()); SessionStore::getInstance().updateSessionTimeout( sessionTimeoutInseconds); } @@ -147,15 +146,14 @@ class ConfigFile if (newSubscription == nullptr) { - BMCWEB_LOG_ERROR - << "Problem reading subscription " - "from persistent store"; + BMCWEB_LOG_ERROR("Problem reading subscription " + "from persistent store"); continue; } - BMCWEB_LOG_DEBUG << "Restored subscription: " - << newSubscription->id << " " - << newSubscription->customText; + BMCWEB_LOG_DEBUG("Restored subscription: {} {}", + newSubscription->id, + newSubscription->customText); EventServiceStore::getInstance() .subscriptionsConfigMap.emplace( newSubscription->id, newSubscription); @@ -251,8 +249,7 @@ class ConfigFile std::shared_ptr<UserSubscription> subValue = it.second; if (subValue->subscriptionType == "SSE") { - BMCWEB_LOG_DEBUG - << "The subscription type is SSE, so skipping."; + BMCWEB_LOG_DEBUG("The subscription type is SSE, so skipping."); continue; } nlohmann::json::object_t headers; |