summaryrefslogtreecommitdiff
path: root/include/async_resolve.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/async_resolve.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/async_resolve.hpp')
-rw-r--r--include/async_resolve.hpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index 2bf511299d..3f31e1383f 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -20,14 +20,14 @@ inline bool endpointFromResolveTuple(const std::vector<uint8_t>& ipAddress,
{
if (ipAddress.size() == 4) // ipv4 address
{
- BMCWEB_LOG_DEBUG << "ipv4 address";
+ BMCWEB_LOG_DEBUG("ipv4 address");
boost::asio::ip::address_v4 ipv4Addr(
{ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]});
endpoint.address(ipv4Addr);
}
else if (ipAddress.size() == 16) // ipv6 address
{
- BMCWEB_LOG_DEBUG << "ipv6 address";
+ BMCWEB_LOG_DEBUG("ipv6 address");
boost::asio::ip::address_v6 ipv6Addr(
{ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3],
ipAddress[4], ipAddress[5], ipAddress[6], ipAddress[7],
@@ -37,7 +37,7 @@ inline bool endpointFromResolveTuple(const std::vector<uint8_t>& ipAddress,
}
else
{
- BMCWEB_LOG_ERROR << "Resolve failed to fetch the IP address";
+ BMCWEB_LOG_ERROR("Resolve failed to fetch the IP address");
return false;
}
return true;
@@ -66,14 +66,14 @@ class Resolver
void async_resolve(const std::string& host, std::string_view port,
ResolveHandler&& handler)
{
- BMCWEB_LOG_DEBUG << "Trying to resolve: " << host << ":" << port;
+ BMCWEB_LOG_DEBUG("Trying to resolve: {}:{}", host, port);
uint16_t portNum = 0;
auto it = std::from_chars(&*port.begin(), &*port.end(), portNum);
if (it.ec != std::errc())
{
- BMCWEB_LOG_ERROR << "Failed to get the Port";
+ BMCWEB_LOG_ERROR("Failed to get the Port");
handler(std::make_error_code(std::errc::invalid_argument),
results_type{});
@@ -90,12 +90,12 @@ class Resolver
results_type endpointList;
if (ec)
{
- BMCWEB_LOG_ERROR << "Resolve failed: " << ec.message();
+ BMCWEB_LOG_ERROR("Resolve failed: {}", ec.message());
handler(ec, endpointList);
return;
}
- BMCWEB_LOG_DEBUG << "ResolveHostname returned: " << hostName << ":"
- << flagNum;
+ BMCWEB_LOG_DEBUG("ResolveHostname returned: {}:{}", hostName,
+ flagNum);
// Extract the IP address from the response
for (const std::tuple<int32_t, int32_t, std::vector<uint8_t>>&
resolveList : resp)
@@ -109,7 +109,8 @@ class Resolver
boost::system::errc::address_not_available);
handler(ecErr, endpointList);
}
- BMCWEB_LOG_DEBUG << "resolved endpoint is : " << endpoint;
+ BMCWEB_LOG_DEBUG("resolved endpoint is : {}",
+ endpoint.address().to_string());
endpointList.push_back(endpoint);
}
// All the resolved data is filled in the endpointList