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/actions/action.hpp b/control/json/actions/action.hpp
index 6cc5bac..a9cd49d 100644
--- a/control/json/actions/action.hpp
+++ b/control/json/actions/action.hpp
@@ -21,7 +21,7 @@
#include "group.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
#include <format>
@@ -35,7 +35,6 @@
{
using json = nlohmann::json;
-using namespace phosphor::logging;
/**
* @class ActionParseError - A parsing error exception
@@ -298,8 +297,7 @@
}
else
{
- log<level::ERR>(
- std::format("Action '{}' is already registered", name).c_str());
+ lg2::error("Action '{NAME}' is already registered", "NAME", name);
throw std::runtime_error("Actions with the same name found");
}
@@ -337,9 +335,9 @@
actions.begin()->first, [](auto list, auto act) {
return std::move(list) + ", " + act.first;
});
- log<level::ERR>(
- std::format("Action '{}' is not registered", name).c_str(),
- entry("AVAILABLE_ACTIONS=%s", acts.c_str()));
+ lg2::error(
+ "Action '{NAME}' is not registered. Available actions are {AVAILABLE_ACTIONS}",
+ "NAME", name, "AVAILABLE_ACTIONS", acts);
throw std::runtime_error("Unsupported action name given");
}
}
diff --git a/control/json/actions/mapped_floor.cpp b/control/json/actions/mapped_floor.cpp
index 7cad6a4..8e1b222 100644
--- a/control/json/actions/mapped_floor.cpp
+++ b/control/json/actions/mapped_floor.cpp
@@ -21,6 +21,7 @@
#include "sdeventplus.hpp"
#include <nlohmann/json.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
#include <format>
@@ -41,10 +42,9 @@
auto newFloor = static_cast<T>(floor) + offset;
if (newFloor < 0)
{
- log<level::ERR>(
- std::format("{}: Floor offset of {} resulted in negative floor",
- actionName, offset)
- .c_str());
+ lg2::error(
+ "{ACTION_NAME}: Floor offset of {FLOOR_OFFSET} resulted in negative floor",
+ "ACTION_NAME", actionName, "FLOOR_OFFSET", offset);
return floor;
}
@@ -403,12 +403,11 @@
{
// If the parameter isn't there, then don't use
// this floor table
- log<level::DEBUG>(
- std::format("{}: Parameter {} specified in the JSON "
- "could not be found",
- ActionBase::getName(),
- std::get<std::string>(groupOrParameter))
- .c_str());
+ lg2::debug(
+ "{ACTION_NAME}: Parameter {PARAMETER} specified in the JSON "
+ "could not be found",
+ "ACTION_NAME", ActionBase::getName(), "PARAMETER",
+ std::get<std::string>(groupOrParameter));
continue;
}
}
diff --git a/control/json/actions/net_target_decrease.cpp b/control/json/actions/net_target_decrease.cpp
index a9fe8d1..9d423de 100644
--- a/control/json/actions/net_target_decrease.cpp
+++ b/control/json/actions/net_target_decrease.cpp
@@ -21,17 +21,15 @@
#include "group.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
-#include <format>
#include <variant>
namespace phosphor::fan::control::json
{
using json = nlohmann::json;
-using namespace phosphor::logging;
NetTargetDecrease::NetTargetDecrease(const json& jsonObj,
const std::vector<Group>& groups) :
@@ -122,12 +120,12 @@
else
{
// Unsupported group member type for this action
- log<level::ERR>(
- std::format("Action {}: Unsupported group member type "
- "given. [object = {} : {} : {}]",
- ActionBase::getName(), member,
- group.getInterface(), group.getProperty())
- .c_str());
+ lg2::error(
+ "Action {ACTION_NAME}: Unsupported group member type "
+ "given. [object = {MEMBER} : {GROUP_INTERFACE} : {GROUP_PROPERTY}]",
+ "ACTION_NAME", ActionBase::getName(), "MEMBER", member,
+ "GROUP_INTERFACE", group.getInterface(),
+ "GROUP_PROPERTY", group.getProperty());
}
}
catch (const std::out_of_range& oore)
diff --git a/control/json/actions/net_target_increase.cpp b/control/json/actions/net_target_increase.cpp
index 9c712a7..08a9a1c 100644
--- a/control/json/actions/net_target_increase.cpp
+++ b/control/json/actions/net_target_increase.cpp
@@ -21,17 +21,15 @@
#include "group.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
-#include <format>
#include <variant>
namespace phosphor::fan::control::json
{
using json = nlohmann::json;
-using namespace phosphor::logging;
NetTargetIncrease::NetTargetIncrease(const json& jsonObj,
const std::vector<Group>& groups) :
@@ -117,13 +115,12 @@
else
{
// Unsupported group member type for this action
- log<level::ERR>(
- std::format(
- "Action {}: Unsupported group member type "
- "given. [object = {} : {} : {}]",
- ActionBase::getName(), member,
- group.getInterface(), group.getProperty())
- .c_str());
+ lg2::error(
+ "Action {ACTION_NAME}: Unsupported group member type "
+ "given. [object = {MEMBER} : {GROUP_INTERFACE} : {GROUP_PROPERTY}]",
+ "ACTION_NAME", ActionBase::getName(), "MEMBER",
+ member, "GROUP_INTERFACE", group.getInterface(),
+ "GROUP_PROPERTY", group.getProperty());
}
}
catch (const std::out_of_range& oore)
diff --git a/control/json/actions/pcie_card_floors.cpp b/control/json/actions/pcie_card_floors.cpp
index a5cfee5..33cedfb 100644
--- a/control/json/actions/pcie_card_floors.cpp
+++ b/control/json/actions/pcie_card_floors.cpp
@@ -20,6 +20,8 @@
#include "sdbusplus.hpp"
#include "sdeventplus.hpp"
+#include <phosphor-logging/lg2.hpp>
+
namespace phosphor::fan::control::json
{
@@ -66,10 +68,9 @@
{
if (group.getInterface() != powerStateIface)
{
- log<level::DEBUG>(
- std::format("Wrong interface {} in PCIe card floor group",
- group.getInterface())
- .c_str());
+ lg2::debug(
+ "Wrong interface {GROUP_INTERFACE} in PCIe card floor group",
+ "GROUP_INTERFACE", group.getInterface());
continue;
}
@@ -84,9 +85,8 @@
}
catch (const std::out_of_range& oore)
{
- log<level::ERR>(
- std::format("Could not get power state for {}", slotPath)
- .c_str());
+ lg2::error("Could not get power state for {SLOT_PATH}",
+ "SLOT_PATH", slotPath);
continue;
}
@@ -187,11 +187,10 @@
}
catch (const std::out_of_range& oore)
{
- log<level::ERR>(
- std::format(
- "{}: Could not get PCIeDevice property {} {} from cache ",
- ActionBase::getName(), objectPath, propertyName)
- .c_str());
+ lg2::error(
+ "{ACTION_NAME}: Could not get PCIeDevice property {OBJECT_PATH} {PROPERTY_NAME} from cache ",
+ "ACTION_NAME", ActionBase::getName(), "OBJECT_PATH", objectPath,
+ "PROPERTY_NAME", propertyName);
throw;
}
@@ -202,11 +201,11 @@
}
catch (const std::invalid_argument& e)
{
- log<level::INFO>(
- std::format("{}: {} has invalid PCIeDevice property {} value: {}",
- ActionBase::getName(), objectPath, propertyName,
- std::get<std::string>(variantValue))
- .c_str());
+ lg2::info(
+ "{ACTION_NAME}: {OBJECT_PATH} has invalid PCIeDevice property {PROPERTY_NAME} value: {VALUE}",
+ "ACTION_NAME", ActionBase::getName(), "OBJECT_PATH", objectPath,
+ "PROPERTY_NAME", propertyName, "VALUE",
+ std::get<std::string>(variantValue));
throw;
}
}
diff --git a/control/json/actions/request_target_base.cpp b/control/json/actions/request_target_base.cpp
index f52a19b..186e611 100644
--- a/control/json/actions/request_target_base.cpp
+++ b/control/json/actions/request_target_base.cpp
@@ -20,16 +20,14 @@
#include "group.hpp"
#include <nlohmann/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
-#include <format>
namespace phosphor::fan::control::json
{
using json = nlohmann::json;
-using namespace phosphor::logging;
RequestTargetBase::RequestTargetBase(const json& jsonObj,
const std::vector<Group>& groups) :
@@ -73,12 +71,12 @@
else
{
// Unsupported group member type for this action
- log<level::ERR>(
- std::format("Action {}: Unsupported group member type "
- "given. [object = {} : {} : {}]",
- getName(), member, group.getInterface(),
- group.getProperty())
- .c_str());
+ lg2::error(
+ "Action {ACTION_NAME}: Unsupported group member type "
+ "given. [object = {MEMBER} : {GROUP_INTERFACE} : {GROUP_PROPERTY}]",
+ "ACTION_NAME", getName(), "MEMBER", member,
+ "GROUP_INTERFACE", group.getInterface(),
+ "GROUP_PROPERTY", group.getProperty());
}
}
catch (const std::out_of_range& oore)
diff --git a/control/json/actions/set_parameter_from_group_max.cpp b/control/json/actions/set_parameter_from_group_max.cpp
index 811f37c..e019e7c 100644
--- a/control/json/actions/set_parameter_from_group_max.cpp
+++ b/control/json/actions/set_parameter_from_group_max.cpp
@@ -17,13 +17,12 @@
#include "../manager.hpp"
-#include <format>
+#include <phosphor-logging/lg2.hpp>
namespace phosphor::fan::control::json
{
using json = nlohmann::json;
-using namespace phosphor::logging;
SetParameterFromGroupMax::SetParameterFromGroupMax(
const json& jsonObj, const std::vector<Group>& groups) :
@@ -69,12 +68,12 @@
!std::is_same_v<int32_t, V> &&
!std::is_same_v<int64_t, V>)
{
- log<level::ERR>(std::format("{}: Group {} has more "
- "than one member but "
- "isn't numeric",
- ActionBase::getName(),
- group.getName())
- .c_str());
+ lg2::error(
+ "{ACTION_NAME}: Group {GROUP_NAME} has more "
+ "than one member but "
+ "isn't numeric",
+ "ACTION_NAME", ActionBase::getName(),
+ "GROUP_NAME", group.getName());
invalid = true;
}
},
@@ -104,10 +103,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("{}: Could not perform modifier operation: {}",
- ActionBase::getName(), e.what())
- .c_str());
+ lg2::error(
+ "{ACTION_NAME}: Could not perform modifier operation: {ERROR}",
+ "ACTION_NAME", ActionBase::getName(), "ERROR", e);
return;
}
}
diff --git a/control/json/actions/target_from_group_max.cpp b/control/json/actions/target_from_group_max.cpp
index d92457d..c4a0427 100644
--- a/control/json/actions/target_from_group_max.cpp
+++ b/control/json/actions/target_from_group_max.cpp
@@ -17,7 +17,8 @@
#include "../manager.hpp"
-#include <format>
+#include <phosphor-logging/lg2.hpp>
+
#include <iostream>
namespace phosphor::fan::control::json
@@ -27,7 +28,6 @@
size_t TargetFromGroupMax::_groupIndexCounter = 0;
using json = nlohmann::json;
-using namespace phosphor::logging;
TargetFromGroupMax::TargetFromGroupMax(const json& jsonObj,
const std::vector<Group>& groups) :
@@ -190,11 +190,10 @@
!std::is_same_v<int32_t, V> &&
!std::is_same_v<int64_t, V>)
{
- log<level::ERR>(
- std::format("{}: Group {}'s member "
- "isn't numeric",
- ActionBase::getName(), group.getName())
- .c_str());
+ lg2::error("{ACTION_NAME}: Group {GROUP_NAME}'s member "
+ "isn't numeric",
+ "ACTION_NAME", ActionBase::getName(),
+ "GROUP_NAME", group.getName());
invalid = true;
}
},