use std::format instead of fmt::format
The std::format is sufficient for the uses in this repository except
for in one file (override_fan_target.cpp, since P2286 isn't supported
by GCC yet). Switch to std::format whenever possible.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib2576fb530a4d7ce238e1b0bd95b40b476ec2107
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 2c29cb3..fc408de 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -21,10 +21,10 @@
#include "types.hpp"
#include "utility.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/log.hpp>
+#include <format>
+
namespace phosphor
{
namespace fan
@@ -122,7 +122,7 @@
if (!_present)
{
getLogger().log(
- fmt::format("On startup, fan {} is missing", _name));
+ std::format("On startup, fan {} is missing", _name));
if (_system.isPowerOn() && _fanMissingErrorTimer)
{
_fanMissingErrorTimer->restartOnce(
@@ -161,7 +161,7 @@
if (!_present)
{
- getLogger().log(fmt::format(
+ getLogger().log(std::format(
"New fan {} interface added and fan is not present", _name));
if (_system.isPowerOn() && _fanMissingErrorTimer)
{
@@ -195,7 +195,7 @@
// The tach property still isn't on D-Bus. Ensure
// sensor is nonfunctional, but skip creating an
// error for it since it isn't a fan problem.
- getLogger().log(fmt::format(
+ getLogger().log(std::format(
"Monitoring starting but {} sensor value not on D-Bus",
sensor->name()));
@@ -384,7 +384,7 @@
// isn't on D-Bus as this isn't a fan hardware problem.
sensor.setFunctional(!sensor.functional(), !sensor.hasOwner());
- getLogger().log(fmt::format(
+ getLogger().log(std::format(
"Setting tach sensor {} functional state to {}. "
"[target = {}, actual = {}, allowed range = ({} - {}) "
"owned = {}]",
@@ -402,7 +402,7 @@
if (!_setFuncOnPresent && !_functional &&
!(numNonFuncSensors >= _numSensorFailsForNonFunc))
{
- getLogger().log(fmt::format("Setting fan {} to functional, number "
+ getLogger().log(std::format("Setting fan {} to functional, number "
"of nonfunctional sensors = {}",
_name, numNonFuncSensors));
updateInventory(true);
@@ -413,7 +413,7 @@
// the fan to nonfunctional.
if (_functional && (numNonFuncSensors >= _numSensorFailsForNonFunc))
{
- getLogger().log(fmt::format("Setting fan {} to nonfunctional, "
+ getLogger().log(std::format("Setting fan {} to nonfunctional, "
"number of nonfunctional sensors = {}",
_name, numNonFuncSensors));
updateInventory(false);
@@ -451,7 +451,7 @@
dbusError = true;
getLogger().log(
- fmt::format("D-Bus Exception reading/updating inventory : {}",
+ std::format("D-Bus Exception reading/updating inventory : {}",
e.what()),
Logger::error);
}
@@ -475,7 +475,7 @@
_present = std::get<bool>(presentProp->second);
getLogger().log(
- fmt::format("Fan {} presence state change to {}", _name, _present));
+ std::format("Fan {} presence state change to {}", _name, _present));
if (_present && _setFuncOnPresent)
{
@@ -550,7 +550,7 @@
// Properties still aren't on D-Bus. Let startMonitor()
// deal with it, or maybe System::powerStateChanged() if
// there aren't any sensors at all on D-Bus.
- getLogger().log(fmt::format(
+ getLogger().log(std::format(
"At power on, tach sensor {} value not on D-Bus",
sensor->name()));
}
@@ -572,7 +572,7 @@
else
{
getLogger().log(
- fmt::format("At power on, fan {} is missing", _name));
+ std::format("At power on, fan {} is missing", _name));
if (_fanMissingErrorTimer)
{
diff --git a/monitor/fan_error.cpp b/monitor/fan_error.cpp
index f0a6f32..396b731 100644
--- a/monitor/fan_error.cpp
+++ b/monitor/fan_error.cpp
@@ -73,7 +73,7 @@
if (_fd() == -1)
{
auto e = errno;
- getLogger().log(fmt::format("Could not open FFDC file {}. errno {}",
+ getLogger().log(std::format("Could not open FFDC file {}. errno {}",
_name.string(), e));
}
}
@@ -120,7 +120,7 @@
catch (const DBusError& e)
{
getLogger().log(
- fmt::format("Call to create a {} error for fan {} failed: {}",
+ std::format("Call to create a {} error for fan {} failed: {}",
_errorName, _fanName, e.what()),
Logger::error);
}
@@ -164,7 +164,7 @@
catch (const std::exception& e)
{
log<level::ERR>(
- fmt::format("Could not save log contents in FFDC. Error msg: {}",
+ std::format("Could not save log contents in FFDC. Error msg: {}",
e.what())
.c_str());
}
@@ -194,7 +194,7 @@
else
{
auto e = errno;
- getLogger().log(fmt::format("Failed called to mkstemp, errno = {}", e),
+ getLogger().log(std::format("Failed called to mkstemp, errno = {}", e),
Logger::error);
}
return nullptr;
diff --git a/monitor/json_parser.cpp b/monitor/json_parser.cpp
index 4d06540..b5b7291 100644
--- a/monitor/json_parser.cpp
+++ b/monitor/json_parser.cpp
@@ -23,12 +23,11 @@
#include "tach_sensor.hpp"
#include "types.hpp"
-#include <fmt/format.h>
-
#include <nlohmann/json.hpp>
#include <phosphor-logging/log.hpp>
#include <algorithm>
+#include <format>
#include <map>
#include <memory>
#include <optional>
@@ -213,7 +212,7 @@
auto deviation = fan["deviation"].get<size_t>();
if (100 < deviation)
{
- auto msg = fmt::format(
+ auto msg = std::format(
"Invalid deviation of {} found, must be between 0 and 100",
deviation);
@@ -230,7 +229,7 @@
if (100 < upperDeviation)
{
auto msg =
- fmt::format("Invalid upper_deviation of {} found, must "
+ std::format("Invalid upper_deviation of {} found, must "
"be between 0 and 100",
upperDeviation);
@@ -409,7 +408,7 @@
}
else if (state != "runtime")
{
- auto msg = fmt::format("Invalid power off state entry {}", state);
+ auto msg = std::format("Invalid power off state entry {}", state);
log<level::ERR>(msg.c_str());
throw std::runtime_error(msg.c_str());
}
@@ -449,7 +448,7 @@
else
{
auto msg =
- fmt::format("Invalid power off cause {} in power off config JSON",
+ std::format("Invalid power off cause {} in power off config JSON",
powerOffCause);
log<level::ERR>(msg.c_str());
throw std::runtime_error(msg.c_str());
@@ -509,7 +508,7 @@
}
else
{
- auto msg = fmt::format("Invalid 'type' entry {} in power off config",
+ auto msg = std::format("Invalid 'type' entry {} in power off config",
type);
log<level::ERR>(msg.c_str());
throw std::runtime_error(msg.c_str());
diff --git a/monitor/power_interface.cpp b/monitor/power_interface.cpp
index f6589b8..dbfcfda 100644
--- a/monitor/power_interface.cpp
+++ b/monitor/power_interface.cpp
@@ -49,7 +49,7 @@
catch (const std::exception& e)
{
getLogger().log(
- fmt::format("Caught exception while creating BMC dump: {}",
+ std::format("Caught exception while creating BMC dump: {}",
e.what()),
Logger::error);
}
diff --git a/monitor/power_off_action.hpp b/monitor/power_off_action.hpp
index c833038..6d7580b 100644
--- a/monitor/power_off_action.hpp
+++ b/monitor/power_off_action.hpp
@@ -4,13 +4,12 @@
#include "power_interface.hpp"
#include "sdbusplus.hpp"
-#include <fmt/format.h>
-
#include <sdeventplus/clock.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/utility/timer.hpp>
#include <chrono>
+#include <format>
namespace phosphor::fan::monitor
{
@@ -113,7 +112,7 @@
catch (const std::exception& e)
{
getLogger().log(
- fmt::format("Caught exception while creating BMC dump: {}",
+ std::format("Caught exception while creating BMC dump: {}",
e.what()),
Logger::error);
}
@@ -215,7 +214,7 @@
}
getLogger().log(
- fmt::format("Action '{}' executing hard power off", name()));
+ std::format("Action '{}' executing hard power off", name()));
_powerIface->hardPowerOff();
createBmcDump();
@@ -307,7 +306,7 @@
}
getLogger().log(
- fmt::format("Action '{}' executing soft power off", name()));
+ std::format("Action '{}' executing soft power off", name()));
_powerIface->softPowerOff();
createBmcDump();
@@ -380,7 +379,7 @@
void start() override
{
getLogger().log(
- fmt::format("Action {}: Starting service mode timer", name()));
+ std::format("Action {}: Starting service mode timer", name()));
_serviceModeTimer.restartOnce(_serviceModeDelay);
}
@@ -393,7 +392,7 @@
*/
void serviceModeTimerExpired()
{
- getLogger().log(fmt::format(
+ getLogger().log(std::format(
"Action {}: Service mode timer expired, starting meltdown timer",
name()));
@@ -408,7 +407,7 @@
*/
void meltdownTimerExpired()
{
- getLogger().log(fmt::format(
+ getLogger().log(std::format(
"Action {}: Meltdown timer expired, executing hard power off",
name()));
diff --git a/monitor/power_off_rule.hpp b/monitor/power_off_rule.hpp
index 3172bd5..ad17870 100644
--- a/monitor/power_off_rule.hpp
+++ b/monitor/power_off_rule.hpp
@@ -84,7 +84,7 @@
{
// Start the action
getLogger().log(
- fmt::format("Starting shutdown action '{}' due to cause '{}'",
+ std::format("Starting shutdown action '{}' due to cause '{}'",
_action->name(), _cause->name()));
_active = true;
@@ -95,13 +95,13 @@
// Attempt to cancel the action, but don't force it
if (_action->cancel(false))
{
- getLogger().log(fmt::format("Stopped shutdown action '{}'",
+ getLogger().log(std::format("Stopped shutdown action '{}'",
_action->name()));
_active = false;
}
else
{
- getLogger().log(fmt::format(
+ getLogger().log(std::format(
"Could not stop shutdown action '{}'", _action->name()));
}
}
diff --git a/monitor/system.cpp b/monitor/system.cpp
index 4a33bb5..bb2e95e 100644
--- a/monitor/system.cpp
+++ b/monitor/system.cpp
@@ -167,7 +167,7 @@
if (serviceObjects.end() == itServ || itServ->second.empty())
{
getLogger().log(
- fmt::format("Fan sensor entry {} not found in D-Bus",
+ std::format("Fan sensor entry {} not found in D-Bus",
sensor->name()),
Logger::error);
continue;
@@ -304,7 +304,7 @@
bool hasOwner = !newOwner.empty() && oldOwner.empty();
std::string stateStr(hasOwner ? "online" : "offline");
- getLogger().log(fmt::format("Changing sensors for service {} to {}",
+ getLogger().log(std::format("Changing sensors for service {} to {}",
serviceName, stateStr),
Logger::info);
@@ -429,7 +429,7 @@
std::string fanPath{util::INVENTORY_PATH + fan.getName()};
getLogger().log(
- fmt::format("Creating event log for faulted fan {} sensor {}", fanPath,
+ std::format("Creating event log for faulted fan {} sensor {}", fanPath,
sensor.name()),
Logger::error);
@@ -473,7 +473,7 @@
std::string fanPath{util::INVENTORY_PATH + fan.getName()};
getLogger().log(
- fmt::format("Creating event log for missing fan {}", fanPath),
+ std::format("Creating event log for missing fan {}", fanPath),
Logger::error);
auto error = std::make_unique<FanError>(
@@ -568,7 +568,7 @@
catch (const std::exception& e)
{
getLogger().log(
- fmt::format("Caught exception while creating BMC dump: {}",
+ std::format("Caught exception while creating BMC dump: {}",
e.what()),
Logger::error);
}
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index 3030d5c..1d92231 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -19,12 +19,11 @@
#include "sdbusplus.hpp"
#include "utility.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/log.hpp>
#include <filesystem>
+#include <format>
#include <functional>
#include <optional>
#include <utility>
@@ -321,7 +320,7 @@
if (!timerRunning() || mode != _timerMode)
{
log<level::DEBUG>(
- fmt::format("Start timer({}) on tach sensor {}. [delay = {}s]",
+ std::format("Start timer({}) on tach sensor {}. [delay = {}s]",
static_cast<int>(mode), _name,
duration_cast<seconds>(getDelay(mode)).count())
.c_str());
@@ -357,7 +356,7 @@
{
++_counter;
log<level::DEBUG>(
- fmt::format(
+ std::format(
"Incremented error counter on {} to {} (threshold {})",
_name, _counter, _threshold)
.c_str());
@@ -369,7 +368,7 @@
{
--_counter;
log<level::DEBUG>(
- fmt::format(
+ std::format(
"Decremented error counter on {} to {} (threshold {})",
_name, _counter, _threshold)
.c_str());
@@ -382,7 +381,7 @@
if (_countTimer)
{
log<level::DEBUG>(
- fmt::format("Starting count timer on sensor {}", _name).c_str());
+ std::format("Starting count timer on sensor {}", _name).c_str());
_countTimer->restart(std::chrono::seconds(_countInterval));
}
}
@@ -392,7 +391,7 @@
if (_countTimer && _countTimer->isEnabled())
{
log<level::DEBUG>(
- fmt::format("Stopping count timer on tach sensor {}.", _name)
+ std::format("Stopping count timer on tach sensor {}.", _name)
.c_str());
_countTimer->setEnabled(false);
}
diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp
index b4dc5b5..1468ab1 100644
--- a/monitor/tach_sensor.hpp
+++ b/monitor/tach_sensor.hpp
@@ -1,7 +1,5 @@
#pragma once
-#include <fmt/format.h>
-
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
@@ -11,6 +9,7 @@
#include <chrono>
#include <deque>
+#include <format>
#include <optional>
#include <utility>
@@ -287,7 +286,7 @@
inline void stopTimer()
{
phosphor::logging::log<phosphor::logging::level::DEBUG>(
- fmt::format("Stop running timer on tach sensor {}.", _name)
+ std::format("Stop running timer on tach sensor {}.", _name)
.c_str());
_timer.setEnabled(false);
}