Implementing Phosphor-Logging/LG2 logging
This commit introduces changes in the openpower-debug-collector
repository to implement structured logging using the LG2
framework. The existing log calls in the repository,
have been replaced with LG2 logging, facilitates better
log tracking and troubleshooting by offering improved
detail in JSON object values.
Change-Id: Iabea1d0044d27a286f73e34588205b45952ae146
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/watchdog/watchdog_dbus.cpp b/watchdog/watchdog_dbus.cpp
index 1606be1..ed7e750 100644
--- a/watchdog/watchdog_dbus.cpp
+++ b/watchdog/watchdog_dbus.cpp
@@ -1,10 +1,9 @@
#include <unistd.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <watchdog_dbus.hpp>
#include <watchdog_logging.hpp>
-#include <format>
#include <string>
#include <vector>
@@ -13,8 +12,6 @@
namespace dump
{
-using namespace phosphor::logging;
-
int dbusMethod(const std::string& path, const std::string& interface,
const std::string& function, sdbusplus::message_t& method,
const std::string& extended)
@@ -71,16 +68,16 @@
else
{
// This trace will be picked up in event log
- log<level::INFO>("dbusMethod service not found");
+ lg2::info("dbusMethod service not found");
std::string traceMsgPath = std::string(path, maxTraceLen);
- log<level::INFO>(traceMsgPath.c_str());
+ lg2::info(traceMsgPath.c_str());
std::string traceMsgIface = std::string(interface, maxTraceLen);
- log<level::INFO>(traceMsgIface.c_str());
+ lg2::info(traceMsgIface.c_str());
}
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Error in dbusMethod", entry("ERROR=%s", e.what()));
+ lg2::error("Error in dbusMethod ({ERROR})", "ERROR", e);
}
return rc;
@@ -122,8 +119,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Error in createPel CreatePELWithFFDCFiles",
- entry("ERROR=%s", e.what()));
+ lg2::error("Error in createPel CreatePELWithFFDCFiles ({ERROR})",
+ "ERROR", e);
}
}
@@ -159,10 +156,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- std::format("Failed to read CurrentHostState property ({})",
- e.what())
- .c_str());
+ lg2::error("Failed to read CurrentHostState property ({ERROR})",
+ "ERROR", e);
}
}