Add fmtlib for phosphor-debug-collector
Call fmtlib to get additional information from journal.
Tested: built phosphor-debug-collector successfully
and Unit Test passes.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ibe65637a0b29b76269fb4bc3f498438901c9306a
diff --git a/dump_manager_bmc.cpp b/dump_manager_bmc.cpp
index f570181..2cf23aa 100644
--- a/dump_manager_bmc.cpp
+++ b/dump_manager_bmc.cpp
@@ -7,6 +7,7 @@
#include "xyz/openbmc_project/Common/error.hpp"
#include "xyz/openbmc_project/Dump/Create/error.hpp"
+#include <fmt/core.h>
#include <sys/inotify.h>
#include <unistd.h>
@@ -60,10 +61,10 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(e.what());
- log<level::ERR>("Error in creating dump entry",
- entry("OBJECTPATH=%s", objPath.c_str()),
- entry("ID=%d", id));
+ log<level::ERR>(fmt::format("Error in creating dump entry, "
+ "errormsg({}), OBJECTPATH({}), ID({})",
+ e.what(), objPath.c_str(), id)
+ .c_str());
elog<InternalFailure>();
}
@@ -94,8 +95,11 @@
// dreport script execution is failed.
auto error = errno;
- log<level::ERR>("Error occurred during dreport function execution",
- entry("ERRNO=%d", error));
+ log<level::ERR>(
+ fmt::format(
+ "Error occurred during dreport function execution, errno({})",
+ error)
+ .c_str());
elog<InternalFailure>();
}
else if (pid > 0)
@@ -105,15 +109,20 @@
if (0 > rc)
{
// Failed to add to event loop
- log<level::ERR>("Error occurred during the sd_event_add_child call",
- entry("RC=%d", rc));
+ log<level::ERR>(
+ fmt::format(
+ "Error occurred during the sd_event_add_child call, rc({})",
+ rc)
+ .c_str());
elog<InternalFailure>();
}
}
else
{
auto error = errno;
- log<level::ERR>("Error occurred during fork", entry("ERRNO=%d", error));
+ log<level::ERR>(
+ fmt::format("Error occurred during fork, errno({})", error)
+ .c_str());
elog<InternalFailure>();
}
@@ -132,8 +141,9 @@
if (!((std::regex_search(name, match, file_regex)) && (match.size() > 0)))
{
- log<level::ERR>("Invalid Dump file name",
- entry("FILENAME=%s", file.filename().c_str()));
+ log<level::ERR>(fmt::format("Invalid Dump file name, FILENAME({})",
+ file.filename().c_str())
+ .c_str());
return;
}
@@ -164,13 +174,13 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(e.what());
- log<level::ERR>("Error in creating dump entry",
- entry("OBJECTPATH=%s", objPath.c_str()),
- entry("ID=%d", id),
- entry("TIMESTAMP=%ull", stoull(msString)),
- entry("SIZE=%d", std::filesystem::file_size(file)),
- entry("FILENAME=%s", file.c_str()));
+ log<level::ERR>(
+ fmt::format(
+ "Error in creating dump entry, errormsg({}), OBJECTPATH({}), "
+ "ID({}), TIMESTAMP({}), SIZE({}), FILENAME({})",
+ e.what(), objPath.c_str(), id, stoull(msString),
+ std::filesystem::file_size(file), file.filename().c_str())
+ .c_str());
return;
}
}