Add phosphor log
For event logging and state transition logging using phosphor log
instead of cerr.
Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
Change-Id: I106ba6340e03fff4317d4f8edd8d2979b7478f03
diff --git a/power-control-x86/src/power_control.cpp b/power-control-x86/src/power_control.cpp
index 20ea9cd..4f4d180 100644
--- a/power-control-x86/src/power_control.cpp
+++ b/power-control-x86/src/power_control.cpp
@@ -25,6 +25,7 @@
#include <fstream>
#include <gpiod.hpp>
#include <iostream>
+#include <phosphor-logging/log.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <string_view>
@@ -185,7 +186,10 @@
}
static void logStateTransition(const PowerState state)
{
- std::cerr << "Moving to \"" << getPowerStateName(state) << "\" state.\n";
+ std::string logMsg = "Moving to \"" + getPowerStateName(state) + "\" state";
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ logMsg.c_str(),
+ phosphor::logging::entry("STATE=%s", getPowerStateName(state).c_str()));
}
enum class Event
@@ -286,8 +290,11 @@
}
static void logEvent(const std::string_view stateHandler, const Event event)
{
- std::cerr << stateHandler << ": " << getEventName(event)
- << " event received.\n";
+ std::string logMsg{stateHandler};
+ logMsg += ": " + getEventName(event) + " event received";
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ logMsg.c_str(),
+ phosphor::logging::entry("EVENT=%s", getEventName(event).c_str()));
}
// Power state handlers