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_main.cpp b/watchdog/watchdog_main.cpp
index 7ad1ced..b124be3 100644
--- a/watchdog/watchdog_main.cpp
+++ b/watchdog/watchdog_main.cpp
@@ -7,7 +7,7 @@
#include <libphal.H>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <watchdog_common.hpp>
#include <watchdog_dbus.hpp>
#include <watchdog_handler.hpp>
@@ -18,8 +18,6 @@
namespace dump
{
-using namespace phosphor::logging;
-
void triggerHostbootDump(const uint32_t timeout)
{
constexpr auto HOST_STATE_DIAGNOSTIC_MODE =
@@ -71,9 +69,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(std::format("getLocationCode({}): Exception({})",
- pdbg_target_path(procTarget), e.what())
- .c_str());
+ lg2::error("getLocationCode({LOCATION}): Exception({ERROR})",
+ "LOCATION", pdbg_target_path(procTarget), "ERROR", e);
}
}
@@ -92,8 +89,7 @@
catch (const std::exception& e)
{
// Failed to collect FFDC information
- log<level::ERR>(
- std::format("captureFFDC: Exception{}", e.what()).c_str());
+ lg2::error("captureFFDC: Exception{ERROR}", "ERROR", e);
dumpIsRequired = true;
}
@@ -102,13 +98,13 @@
if ((sbeError.errType() == exception::SBE_FFDC_NO_DATA) ||
(sbeError.errType() == exception::SBE_CMD_TIMEOUT) || (dumpIsRequired))
{
- log<level::INFO>("No FFDC data");
+ lg2::info("No FFDC data");
event = "org.open_power.Processor.Error.SbeBootTimeout";
dumpIsRequired = true;
}
else
{
- log<level::ERR>("SBE Boot failure");
+ lg2::error("SBE Boot failure");
event = "org.open_power.Processor.Error.SbeBootFailure";
}
@@ -156,10 +152,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("Skipping SBE special callout due to Exception({})",
- e.what())
- .c_str());
+ lg2::error("Skipping SBE special callout due to Exception({ERROR})",
+ "ERROR", e);
}
auto pelId = createPel(event, additionalData, ffdc);
@@ -174,15 +168,14 @@
if (!dumpAllowed)
{
// Possibly another collection in progress, skip dump collection
- log<level::INFO>("Another collection is in progress, skipping "
- "dump collection");
+ lg2::error("Another collection is in progress, skipping "
+ "dump collection");
return;
}
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("Exception {} occurred", e.what()).c_str());
+ lg2::error("Exception {ERROR} occurred", "ERROR", e);
return;
}