Move the control application to lg2
Update the logging API used for files in phosphor-fan-presence/control
from the older phosphor::logging::log to the more recent lg2::log.
Tested:
* Verified journal traces worked correctly in simulation.
* Modified json to force various property errors and verified
correct key/value pairs in the journalctl output.
Change-Id: If1ac33b90abe2a9baae6f3cc788863bd514fa80e
Signed-off-by: Anwaar Hadi <anwaar.hadi@ibm.com>
diff --git a/control/json/triggers/init.cpp b/control/json/triggers/init.cpp
index 3d9a535..4d24c93 100644
--- a/control/json/triggers/init.cpp
+++ b/control/json/triggers/init.cpp
@@ -22,10 +22,9 @@
#include "trigger_aliases.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
-#include <format>
#include <iterator>
#include <memory>
#include <numeric>
@@ -36,7 +35,6 @@
{
using json = nlohmann::json;
-using namespace phosphor::logging;
void getProperties(Manager* mgr, const Group& group)
{
@@ -107,11 +105,9 @@
// Path and/or interface configured does not exist on dbus?
// TODO How to handle this? Create timer to keep checking for
// object/service to appear? When to stop checking?
- log<level::ERR>(
- std::format(
- "Unable to get service name for path {}, interface {}",
- member, intf)
- .c_str());
+ lg2::error(
+ "Unable to get service name for path {MEMBER}, interface {GROUP_INTERFACE}",
+ "MEMBER", member, "GROUP_INTERFACE", intf);
}
}
catch (const util::DBusMethodError& dme)
@@ -127,10 +123,11 @@
// Path and/or interface configured does not exist on dbus?
// TODO How to handle this? Create timer to keep checking for
// object/service to appear? When to stop checking?
- log<level::ERR>(std::format("Unable to get service({}) owner "
- "state for path {}, interface {}",
- servName, member, intf)
- .c_str());
+ lg2::error(
+ "Unable to get service({SERVICE}) owner "
+ "state for path {MEMBER}, interface {GROUP_INTERFACE}",
+ "SERVICE", servName, "MEMBER", member, "GROUP_INTERFACE",
+ intf);
throw dme;
}
}
@@ -164,12 +161,12 @@
methods.begin()->first, [](auto list, auto method) {
return std::move(list) + ", " + method.first;
});
- auto msg =
- std::format("Event '{}' requires a supported method given to "
- "be init driven, available methods: {}",
- eventName, availMethods);
- log<level::ERR>(msg.c_str());
- throw std::runtime_error(msg.c_str());
+ lg2::error(
+ "Event '{EVENT_NAME}' requires a supported method given to "
+ "be init driven, available methods: {AVAILABLE_METHODS}",
+ "EVENT_NAME", eventName, "AVAILABLE_METHODS", availMethods);
+ throw std::runtime_error(
+ "Event requires a supported method given to be init driven");
}
for (const auto& group : groups)
diff --git a/control/json/triggers/parameter.cpp b/control/json/triggers/parameter.cpp
index 1bec051..5a2d59f 100644
--- a/control/json/triggers/parameter.cpp
+++ b/control/json/triggers/parameter.cpp
@@ -17,7 +17,7 @@
#include "../manager.hpp"
-#include <format>
+#include <phosphor-logging/lg2.hpp>
namespace phosphor::fan::control::json::trigger::parameter
{
@@ -30,10 +30,11 @@
{
if (!jsonObj.contains("parameter"))
{
- auto msg = std::format(
- "Event '{}' parameter trigger is missing 'parameter'", eventName);
- log<level::ERR>(msg.c_str());
- throw std::runtime_error(msg);
+ lg2::error(
+ "Event '{EVENT_NAME}' parameter trigger is missing 'parameter'",
+ "EVENT_NAME", eventName);
+ throw std::runtime_error(
+ "Event parameter trigger is missing 'parameter'");
}
auto name = jsonObj["parameter"].get<std::string>();
diff --git a/control/json/triggers/signal.cpp b/control/json/triggers/signal.cpp
index 39c20b1..d623616 100644
--- a/control/json/triggers/signal.cpp
+++ b/control/json/triggers/signal.cpp
@@ -22,11 +22,10 @@
#include "trigger_aliases.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus/match.hpp>
#include <algorithm>
-#include <format>
#include <functional>
#include <iterator>
#include <memory>
@@ -38,7 +37,6 @@
{
using json = nlohmann::json;
-using namespace phosphor::logging;
using namespace sdbusplus::bus::match;
void subscribe(const std::string& match, SignalPkg&& signalPkg,
@@ -204,11 +202,10 @@
// Path and/or interface configured does not exist on dbus yet?
// TODO How to handle this? Create timer to keep checking for
// service to appear? When to stop checking?
- log<level::ERR>(
- std::format("Events will not be triggered by name owner changed"
- "signals from service of path {}, interface {}",
- member, group.getInterface())
- .c_str());
+ lg2::error(
+ "Events will not be triggered by name owner changed"
+ "signals from service of path {MEMBER}, interface {GROUP_INTERFACE}",
+ "MEMBER", member, "GROUP_INTERFACE", group.getInterface());
}
}
}
@@ -254,12 +251,12 @@
signals.begin()->first, [](auto list, auto signal) {
return std::move(list) + ", " + signal.first;
});
- auto msg =
- std::format("Event '{}' requires a supported signal given to be "
- "triggered by signal, available signals: {}",
- eventName, availSignals);
- log<level::ERR>(msg.c_str());
- throw std::runtime_error(msg.c_str());
+ lg2::error(
+ "Event '{EVENT_NAME}' requires a supported signal given to be "
+ "triggered by signal, available signals: {AVAILABLE_SIGNALS}",
+ "EVENT_NAME", eventName, "AVAILABLE_SIGNALS", availSignals);
+ throw std::runtime_error(
+ "Event requires a supported signal given to be triggered by signal.");
}
return [subscriber = std::move(subscriber),
diff --git a/control/json/triggers/timer.cpp b/control/json/triggers/timer.cpp
index 8acbc41..fd3aa10 100644
--- a/control/json/triggers/timer.cpp
+++ b/control/json/triggers/timer.cpp
@@ -20,23 +20,21 @@
#include "trigger_aliases.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <chrono>
-#include <format>
namespace phosphor::fan::control::json::trigger::timer
{
using json = nlohmann::json;
-using namespace phosphor::logging;
TimerType getType(const json& jsonObj)
{
if (!jsonObj.contains("type"))
{
- log<level::ERR>("Missing required timer trigger type",
- entry("JSON=%s", jsonObj.dump().c_str()));
+ lg2::error("Missing required timer trigger type", "JSON",
+ jsonObj.dump());
throw std::runtime_error("Missing required timer trigger type");
}
auto type = jsonObj["type"].get<std::string>();
@@ -50,10 +48,9 @@
}
else
{
- log<level::ERR>(
- std::format("Timer trigger type '{}' is not supported", type)
- .c_str(),
- entry("AVAILABLE_TYPES={oneshot, repeating}"));
+ lg2::error(
+ "Timer trigger type '{TYPE}' is not supported. Available types are 'oneshot, repeating'",
+ "TYPE", type);
throw std::runtime_error("Unsupported timer trigger type given");
}
}
@@ -62,8 +59,8 @@
{
if (!jsonObj.contains("interval"))
{
- log<level::ERR>("Missing required timer trigger interval",
- entry("JSON=%s", jsonObj.dump().c_str()));
+ lg2::error("Missing required timer trigger interval", "JSON",
+ jsonObj.dump());
throw std::runtime_error("Missing required timer trigger interval");
}
return static_cast<std::chrono::microseconds>(