Implementing Phosphor-Logging/LG2 logging
This commit introduces changes in the phosphor-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.
Test:
- Created BMC dump
- Created system dump
Here is a example
{
"_EXE" : "/tmp/phosphor-dump-manager",
"_MACHINE_ID" : "f9ca96d99c7b4ba688556f632ffeff5d",
"_CAP_EFFECTIVE" : "1ffffffffff",
"LOG2_FMTMSG" : "Invalid Dump file name, FILENAME: {FILENAME}",
"__CURSOR" : "s=721ae7a5b6ed43ec904f2bb03e3c0403;i=2a8d0;\
b=b372b9a5989e46bb8e62b33310e181ea;m=2c05fda2b;t=5fdf0684c1e70;x=1592f60584d6486c",
"CODE_FUNC" : "void phosphor::dump::bmc::Manager::\
createEntry(const std::filesystem::__cxx11::path&)",
"_SYSTEMD_SLICE" : "system-dropbear.slice",
"CODE_LINE" : "174",
"__REALTIME_TIMESTAMP" : "1686583867350640",
"PRIORITY" : "3",
"_SYSTEMD_UNIT" : "dropbear@1-9.3.29.238:22-9.3.84.138:45432.service",
"_PID" : "16209",
"_BOOT_ID" : "b372b9a5989e46bb8e62b33310e181ea",
"_SOURCE_REALTIME_TIMESTAMP" : "1686583867350580",
"_TRANSPORT" : "journal",
"_HOSTNAME" : "openbmc",
"SYSLOG_IDENTIFIER" : "phosphor-dump-manager",
"MESSAGE" : "Invalid Dump file name, \
FILENAME: BMCDUMP.XXXXXXX.0000006.20230612153010",
"CODE_FILE" : \
"/usr/src/debug/phosphor-debug-collector/1.0+gitAUTOINC+a17f1c92ce-r1\
/dump_manager_bmc.cpp",
"_UID" : "0",
"_CMDLINE" : "/tmp/phosphor-dump-manager",
"_RUNTIME_SCOPE" : "system",
"FILENAME" : "BMCDUMP.XXXXXXXX.0000006.20230612153010",
"_SYSTEMD_INVOCATION_ID" : "64a11629aade4c96ab62154cbc4be8b7",
"__MONOTONIC_TIMESTAMP" : "11817441835",
"_SYSTEMD_CGROUP" : "/system.slice/system-dropbear.slice/\
dropbear@1-9.3.29.238:22-9.3.84.138:45432.service",
"_COMM" : "phosphor-dump-m",
"_GID" : "0"
}
Change-Id: I3a52b812b059b64d945493de2e2cc68a43f6d72a
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/bmc_dump_entry.cpp b/bmc_dump_entry.cpp
index 6bdb761..c9fa464 100644
--- a/bmc_dump_entry.cpp
+++ b/bmc_dump_entry.cpp
@@ -3,8 +3,7 @@
#include "dump_manager.hpp"
#include "dump_offload.hpp"
-#include <fmt/core.h>
-
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
namespace phosphor
@@ -25,9 +24,7 @@
catch (const std::filesystem::filesystem_error& e)
{
// Log Error message and continue
- log<level::ERR>(
- fmt::format("Failed to delete dump file, errormsg({})", e.what())
- .c_str());
+ lg2::error("Failed to delete dump file, errormsg: {ERROR}", "ERROR", e);
}
// Remove Dump entry D-bus object
diff --git a/core_manager.cpp b/core_manager.cpp
index 761abcc..1ba0f33 100644
--- a/core_manager.cpp
+++ b/core_manager.cpp
@@ -2,8 +2,7 @@
#include "core_manager.hpp"
-#include <fmt/core.h>
-
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/exception.hpp>
@@ -72,14 +71,12 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- fmt::format("Failed to GetObject on Dump.Internal: {}", e.what())
- .c_str());
+ lg2::error("Failed to GetObject on Dump.Internal: {ERROR}", "ERROR", e);
return;
}
if (mapperResponse.empty())
{
- log<level::ERR>("Error reading mapper response");
+ lg2::error("Error reading mapper response");
return;
}
@@ -93,8 +90,7 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- fmt::format("Failed to create dump: {}", e.what()).c_str());
+ lg2::error("Failed to create dump: {ERROR}", "ERROR", e);
}
}
diff --git a/core_manager_main.cpp b/core_manager_main.cpp
index 7294cb2..7a37a75 100644
--- a/core_manager_main.cpp
+++ b/core_manager_main.cpp
@@ -4,9 +4,8 @@
#include "watch.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
int main()
@@ -20,10 +19,8 @@
auto rc = sd_event_default(&event);
if (rc < 0)
{
- log<level::ERR>(
- fmt::format("Error occurred during the sd_event_default, rc({})",
- rc)
- .c_str());
+ lg2::error("Error occurred during the sd_event_default, rc: {RC}", "RC",
+ rc);
report<InternalFailure>();
return -1;
}
@@ -37,10 +34,8 @@
auto rc = sd_event_loop(eventP.get());
if (rc < 0)
{
- log<level::ERR>(
- fmt::format("Error occurred during the sd_event_loop, rc({})",
- rc)
- .c_str());
+ lg2::error("Error occurred during the sd_event_loop, rc: {RC}",
+ "RC", rc);
elog<InternalFailure>();
}
}
diff --git a/dump-extensions/openpower-dumps/dump_manager_resource.cpp b/dump-extensions/openpower-dumps/dump_manager_resource.cpp
index 93ce98c..9c39b0a 100644
--- a/dump-extensions/openpower-dumps/dump_manager_resource.cpp
+++ b/dump-extensions/openpower-dumps/dump_manager_resource.cpp
@@ -7,10 +7,9 @@
#include "resource_dump_entry.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace openpower
{
@@ -45,11 +44,9 @@
if ((resEntry->sourceDumpId() == dumpId) &&
(resEntry->status() == phosphor::dump::OperationStatus::Completed))
{
- log<level::INFO>(
- fmt::format("Resource dump entry with source dump id({}) is "
- "already present with entry id({})",
- dumpId, resEntry->getDumpId())
- .c_str());
+ lg2::info("Resource dump entry with source dump id: {DUMP_ID} "
+ "is already present with entry id: {ENTRY_ID}",
+ "DUMP_ID", dumpId, "ENTRY_ID", resEntry->getDumpId());
return;
}
@@ -66,11 +63,10 @@
}
if (upEntry != NULL)
{
- log<level::INFO>(
- fmt::format("Resource Dump Notify: Updating dumpId({}) "
- "with source Id({}) Size({})",
- upEntry->getDumpId(), dumpId, size)
- .c_str());
+ lg2::info("Resource Dump Notify: Updating dumpId: {DUMP_ID} with "
+ "source Id: {SOURCE_ID} Size: {SIZE}",
+ "DUMP_ID", upEntry->getDumpId(), "SOURCE_ID", dumpId, "SIZE",
+ size);
upEntry->update(timeStamp, size, dumpId);
return;
}
@@ -85,10 +81,10 @@
try
{
- log<level::INFO>(fmt::format("Resouce Dump Notify: creating new dump "
- "entry dumpId({}) Id({}) Size({})",
- id, dumpId, size)
- .c_str());
+ lg2::info(
+ "Resouce Dump Notify: creating new dump entry dumpId: {DUMP_ID} "
+ "Id: {ID} Size: {SIZE}",
+ "DUMP_ID", id, "ID", dumpId, "SIZE", size);
entries.insert(std::make_pair(
id, std::make_unique<resource::Entry>(
bus, objPath.c_str(), id, timeStamp, size, dumpId,
@@ -98,12 +94,12 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(fmt::format("Error in creating resource dump entry, "
- "errormsg({}),OBJECTPATH({}),ID({}),"
- "TIMESTAMP({}),SIZE({}),SOURCEID({})",
- e.what(), objPath.c_str(), id, timeStamp,
- size, dumpId)
- .c_str());
+ lg2::error(
+ "Error in creating resource dump entry, errormsg: {ERROR}, "
+ "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, "
+ "SIZE: {SIZE}, SOURCEID: {SOURCE_ID}",
+ "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP",
+ timeStamp, "SIZE", size, "SOURCE_ID", dumpId);
report<InternalFailure>();
return;
}
@@ -147,7 +143,7 @@
{
// Host will generate a default dump if no resource selector string
// is provided. The default dump will be a non-disruptive system dump.
- log<level::INFO>(
+ lg2::info(
"VSP string is not provided, a non-disruptive system dump will be "
"generated by the host");
}
@@ -160,10 +156,8 @@
catch (const std::bad_variant_access& e)
{
// Exception will be raised if the input is not string
- log<level::ERR>(
- fmt::format("An invalid vsp string is passed errormsg({})",
- e.what())
- .c_str());
+ lg2::error("An invalid vsp string is passed, errormsg: {ERROR}",
+ "ERROR", e);
elog<InvalidArgument>(Argument::ARGUMENT_NAME("VSP_STRING"),
Argument::ARGUMENT_VALUE("INVALID INPUT"));
}
@@ -175,7 +169,7 @@
convertCreateParametersToString(CreateParameters::Password));
if (iter == params.end())
{
- log<level::INFO>("Password is not provided for resource dump");
+ lg2::info("Password is not provided for resource dump");
}
else
{
@@ -186,10 +180,9 @@
catch (const std::bad_variant_access& e)
{
// Exception will be raised if the input is not string
- log<level::ERR>(
- fmt::format("An invalid password string is passed errormsg({})",
- e.what())
- .c_str());
+ lg2::error(
+ "An invalid password string is passed, errormsg: {ERROR}",
+ "ERROR", e);
elog<InvalidArgument>(Argument::ARGUMENT_NAME("PASSWORD"),
Argument::ARGUMENT_VALUE("INVALID INPUT"));
}
@@ -212,12 +205,11 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(
- fmt::format(
- "Error in creating resource dump "
- "entry,errormsg({}),OBJECTPATH({}), VSPSTRING({}), ID({})",
- e.what(), objPath.c_str(), vspString, id)
- .c_str());
+ lg2::error(
+ "Error in creating resource dump entry, errormsg: {ERROR}, "
+ "OBJECTPATH: {OBJECT_PATH}, VSPSTRING: {VSP_STRING}, ID: {ID}",
+ "ERROR", e, "OBJECT_PATH", objPath, "VSP_STRING", vspString, "ID",
+ id);
elog<InternalFailure>();
return std::string();
}
diff --git a/dump-extensions/openpower-dumps/dump_manager_system.cpp b/dump-extensions/openpower-dumps/dump_manager_system.cpp
index 558b0e3..af8972a 100644
--- a/dump-extensions/openpower-dumps/dump_manager_system.cpp
+++ b/dump-extensions/openpower-dumps/dump_manager_system.cpp
@@ -7,10 +7,9 @@
#include "system_dump_entry.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace openpower
{
@@ -64,12 +63,12 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(
- fmt::format(
- "Error in creating system dump entry, errormsg({}), "
- "OBJECTPATH({}), ID({}), TIMESTAMP({}),SIZE({}), SOURCEID({})",
- e.what(), objPath.c_str(), id, timeStamp, size, dumpId)
- .c_str());
+ lg2::error(
+ "Error in creating system dump entry, errormsg: {ERROR}, "
+ "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, "
+ "SIZE: {SIZE}, SOURCEID: {SOURCE_ID}",
+ "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP",
+ timeStamp, "SIZE", size, "SOURCE_ID", dumpId);
report<InternalFailure>();
return;
}
@@ -87,7 +86,7 @@
if (params.size() > CREATE_DUMP_MAX_PARAMS)
{
- log<level::WARNING>(
+ lg2::warning(
"System dump accepts not more than 2 additional parameters");
}
@@ -135,11 +134,9 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(
- fmt::format("Error in creating system dump entry, errormsg({}), "
- "OBJECTPATH({}), ID({})",
- e.what(), objPath.c_str(), id)
- .c_str());
+ lg2::error("Error in creating system dump entry, errormsg: {ERROR}, "
+ "OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
+ "ERROR", e, "OBJECT_PATH", objPath, "ID", id);
elog<InternalFailure>();
return std::string();
}
diff --git a/dump-extensions/openpower-dumps/resource_dump_entry.cpp b/dump-extensions/openpower-dumps/resource_dump_entry.cpp
index 3a98d9e..17125fe 100644
--- a/dump-extensions/openpower-dumps/resource_dump_entry.cpp
+++ b/dump-extensions/openpower-dumps/resource_dump_entry.cpp
@@ -4,9 +4,8 @@
#include "host_transport_exts.hpp"
#include "op_dump_consts.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace openpower
@@ -26,11 +25,9 @@
using NotAllowed =
sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
- log<level::INFO>(
- fmt::format(
- "Resource dump offload request id({}) uri({}) source dumpid({})",
- id, uri, sourceDumpId())
- .c_str());
+ lg2::info("Resource dump offload request id: {ID} uri: {URI} "
+ "source dumpid: {SOURCE_DUMP_ID}",
+ "ID", id, "URI", uri, "SOURCE_DUMP_ID", sourceDumpId());
if (!phosphor::dump::isHostRunning())
{
@@ -49,19 +46,16 @@
if ((!offloadUri().empty()) && (phosphor::dump::isHostRunning()))
{
- log<level::ERR>(
- fmt::format("Dump offload is in progress, cannot delete "
- "dump, id({}) srcdumpid({})",
- dumpId, srcDumpID)
- .c_str());
+ lg2::error("Dump offload is in progress, cannot delete dump, "
+ "id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
+ "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
elog<sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed>(
xyz::openbmc_project::Common::NotAllowed::REASON(
"Dump offload is in progress"));
}
- log<level::INFO>(fmt::format("Resource dump delete id({}) srcdumpid({})",
- dumpId, srcDumpID)
- .c_str());
+ lg2::info("Resource dump delete id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
+ "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
// Remove resource dump when host is up by using source dump id
@@ -75,10 +69,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(fmt::format("Error deleting dump from host id({}) "
- "host id({}) error({})",
- dumpId, srcDumpID, e.what())
- .c_str());
+ lg2::error("Error deleting dump from host id: {DUMP_ID} "
+ "host id: {SRC_DUMP_ID} error: {ERROR}",
+ "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID, "ERROR", e);
elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
}
}
diff --git a/dump-extensions/openpower-dumps/system_dump_entry.cpp b/dump-extensions/openpower-dumps/system_dump_entry.cpp
index 39b161d..3d0fb51 100644
--- a/dump-extensions/openpower-dumps/system_dump_entry.cpp
+++ b/dump-extensions/openpower-dumps/system_dump_entry.cpp
@@ -4,9 +4,8 @@
#include "host_transport_exts.hpp"
#include "op_dump_consts.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace openpower
@@ -23,11 +22,9 @@
void Entry::initiateOffload(std::string uri)
{
- log<level::INFO>(
- fmt::format(
- "System dump offload request id({}) uri({}) source dumpid()", id,
- uri, sourceDumpId())
- .c_str());
+ lg2::info("System dump offload request id: {ID} uri: {URI} "
+ "source dumpid: {SOURCE_DUMP_ID}",
+ "ID", id, "URI", uri, "SOURCE_DUMP_ID", sourceDumpId());
phosphor::dump::Entry::initiateOffload(uri);
phosphor::dump::host::requestOffload(sourceDumpId());
}
@@ -39,18 +36,16 @@
if ((!offloadUri().empty()) && (phosphor::dump::isHostRunning()))
{
- log<level::ERR>(
- fmt::format("Dump offload is in progress id({}) srcdumpid({})",
- dumpId, srcDumpID)
- .c_str());
+ lg2::error("Dump offload is in progress id: {DUMP_ID} "
+ "srcdumpid: {SRC_DUMP_ID}",
+ "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
elog<sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed>(
xyz::openbmc_project::Common::NotAllowed::REASON(
"Dump offload is in progress"));
}
- log<level::INFO>(fmt::format("System dump delete id({}) srcdumpid({})",
- dumpId, srcDumpID)
- .c_str());
+ lg2::info("System dump delete id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
+ "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
// Remove host system dump when host is up by using source dump id
// which is present in system dump entry dbus object as a property.
@@ -63,10 +58,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(fmt::format("Error deleting dump from host id({}) "
- "host id({}) error({})",
- dumpId, srcDumpID, e.what())
- .c_str());
+ lg2::error("Error deleting dump from host id: {DUMP_ID} "
+ "host id: {SRC_DUMP_ID} error: {ERROR}",
+ "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID, "ERROR", e);
elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
}
}
diff --git a/dump_manager_bmc.cpp b/dump_manager_bmc.cpp
index 3ef3699..8161f41 100644
--- a/dump_manager_bmc.cpp
+++ b/dump_manager_bmc.cpp
@@ -7,12 +7,12 @@
#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>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdeventplus/exception.hpp>
#include <sdeventplus/source/base.hpp>
@@ -47,8 +47,7 @@
{
if (params.size() > CREATE_DUMP_MAX_PARAMS)
{
- log<level::WARNING>(
- "BMC dump accepts not more than 2 additional parameters");
+ lg2::warning("BMC dump accepts not more than 2 additional parameters");
}
if (Manager::fUserDumpInProgress == true)
@@ -84,10 +83,9 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(fmt::format("Error in creating dump entry, "
- "errormsg({}), OBJECTPATH({}), ID({})",
- e.what(), objPath.c_str(), id)
- .c_str());
+ lg2::error("Error in creating dump entry, errormsg: {ERROR}, "
+ "OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
+ "ERROR", e, "OBJECT_PATH", objPath, "ID", id);
elog<InternalFailure>();
}
@@ -118,10 +116,9 @@
// dreport script execution is failed.
auto error = errno;
- log<level::ERR>(fmt::format("Error occurred during dreport "
- "function execution, errno({})",
- error)
- .c_str());
+ lg2::error("Error occurred during dreport function execution, "
+ "errno: {ERRNO}",
+ "ERRNO", error);
elog<InternalFailure>();
}
else if (pid > 0)
@@ -129,8 +126,7 @@
Child::Callback callback = [this, type, pid](Child&, const siginfo_t*) {
if (type == Type::UserRequested)
{
- log<level::INFO>(
- "User initiated dump completed, resetting flag");
+ lg2::info("User initiated dump completed, resetting flag");
Manager::fUserDumpInProgress = false;
}
this->childPtrMap.erase(pid);
@@ -145,21 +141,18 @@
catch (const sdeventplus::SdEventError& ex)
{
// Failed to add to event loop
- log<level::ERR>(
- fmt::format(
- "Error occurred during the sdeventplus::source::Child "
- "creation ex({})",
- ex.what())
- .c_str());
+ lg2::error(
+ "Error occurred during the sdeventplus::source::Child creation "
+ "ex: {ERROR}",
+ "ERROR", ex);
elog<InternalFailure>();
}
}
else
{
auto error = errno;
- log<level::ERR>(
- fmt::format("Error occurred during fork, errno({})", error)
- .c_str());
+ lg2::error("Error occurred during fork, errno: {ERRNO}", "ERRNO",
+ error);
elog<InternalFailure>();
}
return ++lastEntryId;
@@ -177,9 +170,8 @@
if (!((std::regex_search(name, match, file_regex)) && (match.size() > 0)))
{
- log<level::ERR>(fmt::format("Invalid Dump file name, FILENAME({})",
- file.filename().c_str())
- .c_str());
+ lg2::error("Invalid Dump file name, FILENAME: {FILENAME}", "FILENAME",
+ file);
return;
}
@@ -213,14 +205,13 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(
- fmt::format("Error in creating dump entry, errormsg({}), "
- "OBJECTPATH({}), "
- "ID({}), TIMESTAMP({}), SIZE({}), FILENAME({})",
- e.what(), objPath.c_str(), id, timestamp,
- std::filesystem::file_size(file),
- file.filename().c_str())
- .c_str());
+ lg2::error(
+ "Error in creating dump entry, errormsg: {ERROR}, "
+ "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, "
+ "SIZE: {SIZE}, FILENAME: {FILENAME}",
+ "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP",
+ timestamp, "SIZE", std::filesystem::file_size(file), "FILENAME",
+ file);
return;
}
}
diff --git a/dump_manager_faultlog.cpp b/dump_manager_faultlog.cpp
index 7bb8352..8e0967e 100644
--- a/dump_manager_faultlog.cpp
+++ b/dump_manager_faultlog.cpp
@@ -5,10 +5,9 @@
#include "dump_utils.hpp"
#include "faultlog_dump_entry.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/File/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -33,18 +32,18 @@
sdbusplus::message::object_path
Manager::createDump(phosphor::dump::DumpCreateParams params)
{
- log<level::INFO>("In dump_manager_fault.cpp createDump");
+ lg2::info("In dump_manager_fault.cpp createDump");
// Currently we ignore the parameters.
// TODO phosphor-debug-collector/issues/22: Check parameter values and
// exit early if we don't receive the expected parameters
if (params.empty())
{
- log<level::INFO>("No additional parameters received");
+ lg2::info("No additional parameters received");
}
else
{
- log<level::INFO>("Got additional parameters");
+ lg2::info("Got additional parameters");
}
// Get the originator id and type from params
@@ -70,7 +69,7 @@
if (faultLogFile.is_open())
{
- log<level::INFO>("faultLogFile is open");
+ lg2::info("faultLogFile is open");
faultLogFile << "This is faultlog file #" << idString << " at "
<< std::string(FAULTLOG_DUMP_PATH) + idString << std::endl;
@@ -79,18 +78,17 @@
}
else
{
- log<level::ERR>(fmt::format("Failed to open fault log file at {}, "
- "errno({}), strerror(\"{}\"), "
- "OBJECTPATH({}), ID({})",
- faultLogFilePath.c_str(), errno,
- strerror(errno), objPath.c_str(), id)
- .c_str());
+ lg2::error(
+ "Failed to open fault log file at {FILE_PATH}, errno: {ERRNO}, "
+ "strerror: {STRERROR}, OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
+ "FILE_PATH", faultLogFilePath, "ERRNO", errno, "STRERROR",
+ strerror(errno), "OBJECT_PATH", objPath, "ID", id);
elog<Open>(ErrnoOpen(errno), PathOpen(objPath.c_str()));
}
try
{
- log<level::INFO>("dump_manager_faultlog.cpp: add faultlog entry");
+ lg2::info("dump_manager_faultlog.cpp: add faultlog entry");
uint64_t timestamp =
std::chrono::duration_cast<std::chrono::microseconds>(
@@ -107,16 +105,15 @@
}
catch (const std::invalid_argument& e)
{
- log<level::ERR>(fmt::format("Error in creating dump entry, "
- "errormsg({}), OBJECTPATH({}), ID({})",
- e.what(), objPath.c_str(), id)
- .c_str());
+ lg2::error("Error in creating dump entry, errormsg: {ERROR}, "
+ "OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
+ "ERROR", e, "OBJECT_PATH", objPath, "ID", id);
elog<InternalFailure>();
}
lastEntryId++;
- log<level::INFO>("End of dump_manager_faultlog.cpp createDump");
+ lg2::info("End of dump_manager_faultlog.cpp createDump");
return objPath.string();
}
diff --git a/dump_manager_faultlog.hpp b/dump_manager_faultlog.hpp
index 72dce08..62b0574 100644
--- a/dump_manager_faultlog.hpp
+++ b/dump_manager_faultlog.hpp
@@ -2,10 +2,9 @@
#include "dump_manager.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
#include <xyz/openbmc_project/Dump/Create/server.hpp>
@@ -54,11 +53,12 @@
if (ec)
{
- log<level::ERR>(fmt::format("dump_manager_faultlog directory {} "
- "not created. error_code = {} ({})",
- FAULTLOG_DUMP_PATH, ec.value(),
- ec.message())
- .c_str());
+ auto dir = FAULTLOG_DUMP_PATH;
+ lg2::error(
+ "dump_manager_faultlog directory {DIRECTORY} not created. "
+ "error_code = {ERRNO} ({ERROR_MESSAGE})",
+ "DIRECTORY", dir, "ERRNO", ec.value(), "ERROR_MESSAGE",
+ ec.message());
}
}
@@ -66,7 +66,7 @@
{
// TODO phosphor-debug-collector/issues/21: Restore fault log entries
// after service restart
- log<level::INFO>("dump_manager_faultlog restore not implemented");
+ lg2::info("dump_manager_faultlog restore not implemented");
}
/** @brief Method to create a new fault log dump entry
diff --git a/dump_manager_main.cpp b/dump_manager_main.cpp
index 402cea3..68b0bc0 100644
--- a/dump_manager_main.cpp
+++ b/dump_manager_main.cpp
@@ -9,9 +9,8 @@
#include "watch.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <memory>
@@ -28,10 +27,8 @@
auto rc = sd_event_default(&event);
if (rc < 0)
{
- log<level::ERR>(
- fmt::format("Error occurred during the sd_event_default, rc({})",
- rc)
- .c_str());
+ lg2::error("Error occurred during the sd_event_default, rc: {RC}", "RC",
+ rc);
report<InternalFailure>();
return rc;
}
@@ -42,25 +39,22 @@
sigset_t mask;
if (sigemptyset(&mask) < 0)
{
- log<level::ERR>(
- fmt::format("Unable to initialize signal set, errno({})", errno)
- .c_str());
+ lg2::error("Unable to initialize signal set, errno: {ERRNO}", "ERRNO",
+ errno);
return EXIT_FAILURE;
}
if (sigaddset(&mask, SIGCHLD) < 0)
{
- log<level::ERR>(
- fmt::format("Unable to add signal to signal set, errno({})", errno)
- .c_str());
+ lg2::error("Unable to add signal to signal set, errno: {ERRNO}",
+ "ERRNO", errno);
return EXIT_FAILURE;
}
// Block SIGCHLD first, so that the event loop can handle it
if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0)
{
- log<level::ERR>(
- fmt::format("Unable to block signal, errno({})", errno).c_str());
+ lg2::error("Unable to block signal, errno: {ERRNO}", "ERRNO", errno);
return EXIT_FAILURE;
}
@@ -102,10 +96,8 @@
auto rc = sd_event_loop(eventP.get());
if (rc < 0)
{
- log<level::ERR>(
- fmt::format("Error occurred during the sd_event_loop, rc({})",
- rc)
- .c_str());
+ lg2::error("Error occurred during the sd_event_loop, rc: {RC}",
+ "RC", rc);
elog<InternalFailure>();
}
}
diff --git a/dump_offload.cpp b/dump_offload.cpp
index c590614..bb647e5 100644
--- a/dump_offload.cpp
+++ b/dump_offload.cpp
@@ -2,7 +2,6 @@
#include "dump_offload.hpp"
-#include <fmt/core.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
@@ -11,6 +10,7 @@
#include <dump_utils.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/File/error.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -55,10 +55,8 @@
NULL, &timeVal);
if (retVal <= 0)
{
- log<level::ERR>(
- fmt::format("writeOnUnixSocket: select() failed, errno({})",
- errno)
- .c_str());
+ lg2::error("writeOnUnixSocket: select() failed, errno: {ERRNO}",
+ "ERRNO", errno);
std::string msg = "select() failed " + std::string(strerror(errno));
throw std::runtime_error(msg);
}
@@ -72,10 +70,8 @@
numOfBytesWrote = 0;
continue;
}
- log<level::ERR>(
- fmt::format("writeOnUnixSocket: write() failed, errno({})",
- errno)
- .c_str());
+ lg2::error("writeOnUnixSocket: write() failed, errno: {ERRNO}",
+ "ERRNO", errno);
std::string msg = "write() on socket failed " +
std::string(strerror(errno));
throw std::runtime_error(msg);
@@ -101,7 +97,7 @@
if (strnlen(sockPath.c_str(), sizeof(socketAddr.sun_path)) ==
sizeof(socketAddr.sun_path))
{
- log<level::ERR>("UNIX socket path too long");
+ lg2::error("UNIX socket path too long");
std::string msg = "UNIX socket path is too long " +
std::string(strerror(errno));
throw std::length_error(msg);
@@ -110,26 +106,23 @@
sizeof(socketAddr.sun_path) - 1);
if ((unixSocket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0)) == -1)
{
- log<level::ERR>(
- fmt::format("socketInit: socket() failed, errno({})", errno)
- .c_str());
+ lg2::error("socketInit: socket() failed, errno: {ERRNO}", "ERRNO",
+ errno);
std::string msg = "socket() failed " + std::string(strerror(errno));
throw std::runtime_error(msg);
}
if (bind(unixSocket, (struct sockaddr*)&socketAddr, sizeof(socketAddr)) ==
-1)
{
- log<level::ERR>(
- fmt::format("socketInit: bind() failed, errno({})", errno).c_str());
+ lg2::error("socketInit: bind() failed, errno: {ERRNO}", "ERRNO", errno);
close(unixSocket);
std::string msg = "socket bind failed " + std::string(strerror(errno));
throw std::runtime_error(msg);
}
if (listen(unixSocket, 1) == -1)
{
- log<level::ERR>(
- fmt::format("socketInit: listen() failed, errno({})", errno)
- .c_str());
+ lg2::error("socketInit: listen() failed, errno: {ERRNO}", "ERRNO",
+ errno);
close(unixSocket);
std::string msg = "listen() failed " + std::string(strerror(errno));
throw std::runtime_error(msg);
@@ -162,10 +155,8 @@
int retVal = select(numOfFDs, &readFD, NULL, NULL, &timeVal);
if (retVal <= 0)
{
- log<level::ERR>(
- fmt::format("select() failed, errno({}), DUMP_ID({})", errno,
- dumpId)
- .c_str());
+ lg2::error("select() failed, errno: {ERRNO}, DUMP_ID: {DUMP_ID}",
+ "ERRNO", errno, "DUMP_ID", dumpId);
std::string msg = "select() failed " + std::string(strerror(errno));
throw std::runtime_error(msg);
}
@@ -174,10 +165,9 @@
CustomFd socketFD = accept(unixSocket(), NULL, NULL);
if (socketFD() < 0)
{
- log<level::ERR>(
- fmt::format("accept() failed, errno({}), DUMP_ID({})",
- errno, dumpId)
- .c_str());
+ lg2::error(
+ "accept() failed, errno: {ERRNO}, DUMP_ID: {DUMP_ID}",
+ "ERRNO", errno, "DUMP_ID", dumpId);
std::string msg = "accept() failed " +
std::string(strerror(errno));
throw std::runtime_error(msg);
@@ -187,20 +177,18 @@
if (!infile.good())
{
// Unable to open the dump file
- log<level::ERR>(
- fmt::format("Failed to open the dump from file, errno({}), "
- "DUMPFILE({}), DUMP_ID({})",
- errno, file.c_str(), dumpId)
- .c_str());
+ lg2::error("Failed to open the dump from file, errno: {ERRNO}, "
+ "DUMPFILE: {DUMP_FILE}, DUMP_ID: {DUMP_ID}",
+ "ERRNO", errno, "DUMP_FILE", file, "DUMP_ID",
+ dumpId);
elog<Open>(ErrnoOpen(errno), PathOpen(file.c_str()));
}
infile.exceptions(std::ifstream::failbit | std::ifstream::badbit |
std::ifstream::eofbit);
- log<level::INFO>(fmt::format("Opening File for RW, FILENAME({})",
- file.filename().c_str())
- .c_str());
+ lg2::info("Opening File for RW, FILENAME: {FILENAME}", "FILENAME",
+ file.filename().c_str());
std::filebuf* pbuf = infile.rdbuf();
@@ -221,21 +209,18 @@
{
std::remove(writePath.c_str());
auto err = errno;
- log<level::ERR>(
- fmt::format(
- "Failed to open, errormsg({}), OPENINTERFACE({}), DUMP_ID({})",
- oe.what(), file.c_str(), dumpId)
- .c_str());
+ lg2::error("Failed to open, errormsg: {ERROR}, "
+ "OPENINTERFACE: {OPEN_INTERFACE}, DUMP_ID: {DUMP_ID}",
+ "ERROR", oe, "OPEN_INTERFACE", file, "DUMP_ID", dumpId);
elog<Open>(ErrnoOpen(err), PathOpen(file.c_str()));
}
catch (const std::exception& e)
{
std::remove(writePath.c_str());
auto err = errno;
- log<level::ERR>(fmt::format("Failed to offload dump, errormsg({}), "
- "DUMPFILE({}), DUMP_ID({})",
- e.what(), writePath.c_str(), dumpId)
- .c_str());
+ lg2::error("Failed to offload dump, errormsg: {ERROR}, "
+ "DUMPFILE: {DUMP_FILE}, DUMP_ID: {DUMP_ID}",
+ "ERROR", e, "DUMP_FILE", writePath, "DUMP_ID", dumpId);
elog<Write>(ErrnoWrite(err), PathWrite(writePath.c_str()));
}
std::remove(writePath.c_str());
diff --git a/dump_serialize.cpp b/dump_serialize.cpp
index 0104b83..4d1a485 100644
--- a/dump_serialize.cpp
+++ b/dump_serialize.cpp
@@ -1,9 +1,8 @@
#include "dump_serialize.hpp"
-#include <fmt/core.h>
-
#include <cereal/archives/binary.hpp>
#include <cereal/types/set.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <fstream>
@@ -39,9 +38,7 @@
}
catch (const cereal::Exception& e)
{
- log<level::ERR>(
- fmt::format("Failed to deserialize, errormsg({})", e.what())
- .c_str());
+ lg2::error("Failed to deserialize, errormsg: {ERROR}", "ERROR", e);
std::filesystem::remove(path);
return false;
}
diff --git a/dump_utils.cpp b/dump_utils.cpp
index 236bff0..ee75a4f 100644
--- a/dump_utils.cpp
+++ b/dump_utils.cpp
@@ -1,7 +1,6 @@
#include "dump_utils.hpp"
-#include <fmt/core.h>
-
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
namespace phosphor
@@ -31,19 +30,18 @@
reply.read(response);
if (response.empty())
{
- log<level::ERR>(fmt::format("Error in mapper response for getting "
- "service name, PATH({}), INTERFACE({})",
- path, interface)
- .c_str());
+ lg2::error(
+ "Error in mapper response for getting service name, PATH: "
+ "{PATH}, INTERFACE: {INTERFACE}",
+ "PATH", path, "INTERFACE", interface);
return std::string{};
}
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(fmt::format("Error in mapper method call, "
- "errormsg({}), PATH({}), INTERFACE({})",
- e.what(), path, interface)
- .c_str());
+ lg2::error("Error in mapper method call, errormsg: {ERROR}, "
+ "PATH: {PATH}, INTERFACE: {INTERFACE}",
+ "ERROR", e, "PATH", path, "INTERFACE", interface);
return std::string{};
}
return response[0].first;
@@ -86,20 +84,19 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(fmt::format("D-Bus call exception, OBJPATH({}), "
- "INTERFACE({}), EXCEPTION({})",
- hostStateObjPath, bootProgressInterface,
- e.what())
- .c_str());
+ lg2::error("D-Bus call exception, OBJPATH: {OBJ_PATH}, "
+ "INTERFACE: {INTERFACE}, EXCEPTION: {ERROR}",
+ "OBJ_PATH", hostStateObjPath, "INTERFACE",
+ bootProgressInterface, "ERROR", e);
throw std::runtime_error("Failed to get BootProgress stage");
}
catch (const std::bad_variant_access& e)
{
- log<level::ERR>(
- fmt::format("Exception raised while read BootProgress property "
- "value, OBJPATH({}), INTERFACE({}), EXCEPTION({})",
- hostStateObjPath, bootProgressInterface, e.what())
- .c_str());
+ lg2::error("Exception raised while read BootProgress property value, "
+ "OBJPATH: {OBJ_PATH}, INTERFACE: {INTERFACE}, "
+ "EXCEPTION: {ERROR}",
+ "OBJ_PATH", hostStateObjPath, "INTERFACE",
+ bootProgressInterface, "ERROR", e);
throw std::runtime_error("Failed to get BootProgress stage");
}
diff --git a/dump_utils.hpp b/dump_utils.hpp
index 9f683ad..6e923bc 100644
--- a/dump_utils.hpp
+++ b/dump_utils.hpp
@@ -1,13 +1,12 @@
#pragma once
-
#include "dump_manager.hpp"
-#include <fmt/core.h>
#include <systemd/sd-event.h>
#include <unistd.h>
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/Dump/Create/server.hpp>
@@ -116,7 +115,7 @@
convertCreateParametersToString(CreateParametersXYZ::OriginatorId));
if (iter == params.end())
{
- log<level::INFO>("OriginatorId is not provided");
+ lg2::info("OriginatorId is not provided");
}
else
{
@@ -127,12 +126,9 @@
catch (const std::bad_variant_access& e)
{
// Exception will be raised if the input is not string
- log<level::ERR>(
- fmt::format(
- "An invalid originatorId passed. It should be a string, "
- "errormsg({})",
- e.what())
- .c_str());
+ lg2::error("An invalid originatorId passed. It should be a string, "
+ "errormsg: {ERROR}",
+ "ERROR", e);
elog<InvalidArgument>(Argument::ARGUMENT_NAME("ORIGINATOR_ID"),
Argument::ARGUMENT_VALUE("INVALID INPUT"));
}
@@ -143,8 +139,8 @@
CreateParametersXYZ::OriginatorType));
if (iter == params.end())
{
- log<level::INFO>("OriginatorType is not provided. Replacing the string "
- "with the default value");
+ lg2::info("OriginatorType is not provided. Replacing the string "
+ "with the default value");
originatorType = originatorTypes::Internal;
}
else
@@ -158,10 +154,8 @@
catch (const std::bad_variant_access& e)
{
// Exception will be raised if the input is not string
- log<level::ERR>(fmt::format("An invalid originatorType passed, "
- "errormsg({})",
- e.what())
- .c_str());
+ lg2::error("An invalid originatorType passed, errormsg: {ERROR}",
+ "ERROR", e);
elog<InvalidArgument>(Argument::ARGUMENT_NAME("ORIGINATOR_TYPE"),
Argument::ARGUMENT_VALUE("INVALID INPUT"));
}
diff --git a/elog_watch.cpp b/elog_watch.cpp
index e55211f..00c6dc9 100644
--- a/elog_watch.cpp
+++ b/elog_watch.cpp
@@ -7,10 +7,9 @@
#include "errors_map.hpp"
#include "xyz/openbmc_project/Dump/Create/error.hpp"
-#include <fmt/core.h>
-
#include <cereal/cereal.hpp>
#include <phosphor-logging/elog.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <fstream>
@@ -52,7 +51,7 @@
{
if (!deserialize(ELOG_ID_PERSIST_PATH, elogList))
{
- log<level::ERR>("Error occurred during error id deserialize");
+ lg2::error("Error occurred during error id deserialize");
}
}
}
@@ -70,11 +69,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- fmt::format(
- "Failed to parse elog add signal, errormsg({}), REPLY_SIG({})",
- e.what(), msg.get_signature())
- .c_str());
+ lg2::error("Failed to parse elog add signal, errormsg: {ERROR}, "
+ "REPLY_SIG: {REPLY_SIG}",
+ "ERROR", e, "REPLY_SIG", msg.get_signature());
return;
}
@@ -167,11 +164,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- fmt::format(
- "Failed to parse elog del signal, errormsg({}), REPLY_SIG({})",
- e.what(), msg.get_signature())
- .c_str());
+ lg2::error("Failed to parse elog del signal, errormsg: {ERROR}, "
+ "REPLY_SIG: {REPLY_SIG}",
+ "ERROR", e, "REPLY_SIG", msg.get_signature());
return;
}
diff --git a/faultlog_dump_entry.cpp b/faultlog_dump_entry.cpp
index 897d98b..e5d9c85 100644
--- a/faultlog_dump_entry.cpp
+++ b/faultlog_dump_entry.cpp
@@ -1,7 +1,6 @@
#include "faultlog_dump_entry.hpp"
-#include <fmt/core.h>
-
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
namespace phosphor
@@ -14,7 +13,7 @@
void Entry::delete_()
{
- log<level::INFO>("In faultlog_dump_entry.cpp delete_()");
+ lg2::info("In faultlog_dump_entry.cpp delete_()");
// Delete Dump file from Permanent location
try
@@ -24,9 +23,7 @@
catch (const std::filesystem::filesystem_error& e)
{
// Log Error message and continue
- log<level::ERR>(
- fmt::format("Failed to delete dump file, errormsg({})", e.what())
- .c_str());
+ lg2::error("Failed to delete dump file, errormsg: {ERROR}", "ERROR", e);
}
// Remove Dump entry D-bus object
diff --git a/host-transport-extensions/pldm/common/pldm_utils.cpp b/host-transport-extensions/pldm/common/pldm_utils.cpp
index 7876462..4cd9da1 100644
--- a/host-transport-extensions/pldm/common/pldm_utils.cpp
+++ b/host-transport-extensions/pldm/common/pldm_utils.cpp
@@ -5,9 +5,8 @@
#include "dump_utils.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
namespace phosphor
@@ -27,14 +26,13 @@
if (fd < 0)
{
auto e = errno;
- log<level::ERR>(
- fmt::format(
- "pldm_open failed, errno({}), FD({})", e,
- static_cast<
- std::underlying_type<pldm_requester_error_codes>::type>(fd))
- .c_str());
- elog<NotAllowed>(Reason("Required host dump action via pldm is not "
- "allowed due to pldm_open failed"));
+ lg2::error(
+ "pldm_open failed, errno: {ERRNO}, FD: FD", "ERRNO", e, "FD",
+ static_cast<std::underlying_type<pldm_requester_error_codes>::type>(
+ fd));
+ elog<NotAllowed>(
+ Reason("Required host dump action via pldm is not allowed due "
+ "to pldm_open failed"));
}
return fd;
}
@@ -57,15 +55,12 @@
reply.read(instanceID);
- log<level::INFO>(
- fmt::format("Got instanceId({}) from PLDM eid({})", instanceID, eid)
- .c_str());
+ lg2::info("Got instanceId: {INSTANCE_ID} from PLDM eid: {EID}",
+ "INSTANCE_ID", instanceID, "EID", eid);
}
catch (const sdbusplus::exception::SdBusError& e)
{
- log<level::ERR>(
- fmt::format("Failed to get instance id error({})", e.what())
- .c_str());
+ lg2::error("Failed to get instance id error: {ERROR}", "ERROR", e);
elog<NotAllowed>(Reason("Failure in communicating with pldm service, "
"service may not be running"));
}
diff --git a/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
index 606bd94..b9e2cb0 100644
--- a/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
+++ b/host-transport-extensions/pldm/oem/ibm/pldm_oem_cmds.cpp
@@ -19,13 +19,13 @@
#include "pldm_utils.hpp"
#include "xyz/openbmc_project/Common/error.hpp"
-#include <fmt/core.h>
#include <libpldm/base.h>
#include <libpldm/file_io.h>
#include <libpldm/platform.h>
#include <unistd.h>
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
@@ -72,7 +72,7 @@
std::ifstream eidFile{eidPath};
if (!eidFile.good())
{
- log<level::ERR>("Could not open host EID file");
+ lg2::error("Could not open host EID file");
elog<NotAllowed>(Reason("Required host dump action via pldm is not "
"allowed due to mctp end point read failed"));
}
@@ -86,7 +86,7 @@
}
else
{
- log<level::ERR>("EID file was empty");
+ lg2::error("EID file was empty");
elog<NotAllowed>(
Reason("Required host dump action via pldm is not "
"allowed due to mctp end point read failed"));
@@ -120,29 +120,26 @@
if (rc != PLDM_SUCCESS)
{
- log<level::ERR>(
- fmt::format("Message encode failure. RC({})", rc).c_str());
+ lg2::error("Message encode failure. RC: {RC}", "RC", rc);
elog<NotAllowed>(Reason("Host dump offload via pldm is not "
"allowed due to encode failed"));
}
CustomFd fd(openPLDM());
- log<level::INFO>(
- fmt::format("Sending request to offload dump id({}), eid({})", id, eid)
- .c_str());
+ lg2::info("Sending request to offload dump id: {ID}, eid: {EID}", "ID", id,
+ "EID", eid);
rc = pldm_send(eid, fd(), requestMsg.data(), requestMsg.size());
if (rc < 0)
{
auto e = errno;
- log<level::ERR>(
- fmt::format("pldm_send failed, RC({}), errno({})", rc, e).c_str());
+ lg2::error("pldm_send failed, RC: {RC}, errno: {ERRNO}", "RC", rc,
+ "ERRNO", e);
elog<NotAllowed>(Reason("Host dump offload via pldm is not "
"allowed due to fileack send failed"));
}
- log<level::INFO>(
- fmt::format("Done. PLDM message, id({} )RC({})", id, rc).c_str());
+ lg2::info("Done. PLDM message, id: {ID}, RC: {RC}", "ID", id, "RC", rc);
}
void requestDelete(uint32_t dumpId, uint32_t dumpType)
@@ -176,16 +173,14 @@
if (retCode != PLDM_SUCCESS)
{
- log<level::ERR>(
- fmt::format(
- "Failed to encode pldm FileAck to delete host "
- "dump,SRC_DUMP_ID({}), "
- "PLDM_FILE_IO_TYPE({}),PLDM_RETURN_CODE({})",
- dumpId,
- static_cast<std::underlying_type<pldm_fileio_file_type>::type>(
- pldmDumpType),
- retCode)
- .c_str());
+ lg2::error(
+ "Failed to encode pldm FileAck to delete host dump, "
+ "SRC_DUMP_ID: {SRC_DUMP_ID}, PLDM_FILE_IO_TYPE: {PLDM_DUMP_TYPE}, "
+ "PLDM_RETURN_CODE: {RET_CODE}",
+ "SRC_DUMP_ID", dumpId, "PLDM_DUMP_TYPE",
+ static_cast<std::underlying_type<pldm_fileio_file_type>::type>(
+ pldmDumpType),
+ "RET_CODE", retCode);
elog<NotAllowed>(Reason("Host dump deletion via pldm is not "
"allowed due to encode fileack failed"));
}
@@ -197,24 +192,22 @@
if (retCode != PLDM_REQUESTER_SUCCESS)
{
auto errorNumber = errno;
- log<level::ERR>(
- fmt::format(
- "Failed to send pldm FileAck to delete host dump, "
- "SRC_DUMP_ID({}), PLDM_FILE_IO_TYPE({}), "
- "PLDM_RETURN_CODE({}), ERRNO({}), ERRMSG({})",
- dumpId,
- static_cast<std::underlying_type<pldm_fileio_file_type>::type>(
- pldmDumpType),
- retCode, errorNumber, strerror(errorNumber))
- .c_str());
+ lg2::error(
+ "Failed to send pldm FileAck to delete host dump, "
+ "SRC_DUMP_ID: {SRC_DUMP_ID}, PLDM_FILE_IO_TYPE: {PLDM_DUMP_TYPE}, "
+ "PLDM_RETURN_CODE: {RET_CODE}, ERRNO: {ERRNO}, ERRMSG: {ERRMSG}",
+ "SRC_DUMP_ID", dumpId, "PLDM_DUMP_TYPE",
+ static_cast<std::underlying_type<pldm_fileio_file_type>::type>(
+ pldmDumpType),
+ "RET_CODE", retCode, "ERRNO", errorNumber, "ERRMSG",
+ strerror(errorNumber));
elog<NotAllowed>(Reason("Host dump deletion via pldm is not "
"allowed due to fileack send failed"));
}
- log<level::INFO>(
- fmt::format("Sent request to host to delete the dump, SRC_DUMP_ID({})",
- dumpId)
- .c_str());
+ lg2::info(
+ "Sent request to host to delete the dump, SRC_DUMP_ID: {SRC_DUMP_ID}",
+ "SRC_DUMP_ID", dumpId);
}
} // namespace pldm
} // namespace dump
diff --git a/meson.build b/meson.build
index 3aa2991..1db2e77 100644
--- a/meson.build
+++ b/meson.build
@@ -32,19 +32,6 @@
phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces')
phosphor_logging_dep = dependency('phosphor-logging')
-fmt_dep = dependency('fmt', required: false)
-if not fmt_dep.found()
- fmt_proj = import('cmake').subproject(
- 'fmt',
- cmake_options: [
- '-DCMAKE_POSITION_INDEPENDENT_CODE=ON',
- '-DMASTER_PROJECT=OFF'
- ],
- required: false)
- assert(fmt_proj.found(), 'fmtlib is required')
- fmt_dep = fmt_proj.dependency('fmt')
-endif
-
# Get Cereal dependency.
cereal_dep = dependency('cereal', required: false)
has_cereal = cpp.has_header_symbol(
@@ -181,7 +168,6 @@
sdbusplus_dep,
sdeventplus_dep,
phosphor_logging_dep,
- fmt_dep,
cereal_dep,
]
@@ -205,8 +191,7 @@
phosphor_dump_monitor_dependency = [
phosphor_dbus_interfaces_dep,
- phosphor_logging_dep,
- fmt_dep
+ phosphor_logging_dep
]
phosphor_dump_monitor_install = true
@@ -221,8 +206,7 @@
phosphor_ramoops_monitor_dependency = [
phosphor_dbus_interfaces_dep,
- phosphor_logging_dep,
- fmt_dep
+ phosphor_logging_dep
]
phosphor_ramoops_monitor_install = true
diff --git a/ramoops_manager.cpp b/ramoops_manager.cpp
index af8aa7f..05add0d 100644
--- a/ramoops_manager.cpp
+++ b/ramoops_manager.cpp
@@ -2,8 +2,7 @@
#include "ramoops_manager.hpp"
-#include <fmt/core.h>
-
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <filesystem>
@@ -53,15 +52,13 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- fmt::format("Failed to parse dump create message, error({})",
- e.what())
- .c_str());
+ lg2::error("Failed to parse dump create message, error: {ERROR}",
+ "ERROR", e);
return;
}
if (mapperResponse.empty())
{
- log<level::ERR>("Error reading mapper response");
+ lg2::error("Error reading mapper response");
return;
}
@@ -75,9 +72,8 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- fmt::format("Failed to create ramoops dump, errormsg({})", e.what())
- .c_str());
+ lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR",
+ e);
}
}
diff --git a/ramoops_manager_main.cpp b/ramoops_manager_main.cpp
index e352a2d..b737230 100644
--- a/ramoops_manager_main.cpp
+++ b/ramoops_manager_main.cpp
@@ -2,19 +2,16 @@
#include "ramoops_manager.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
int main()
{
fs::path filePath(SYSTEMD_PSTORE_PATH);
if (!fs::exists(filePath))
{
- log<level::ERR>(
- fmt::format("Pstore file path is not exists, FILE_PATH({})",
- SYSTEMD_PSTORE_PATH)
- .c_str());
+ lg2::error("Pstore file path is not exists, FILE_PATH: {FILE_PATH}",
+ "FILE_PATH", filePath);
return EXIT_FAILURE;
}
diff --git a/subprojects/fmt.wrap b/subprojects/fmt.wrap
deleted file mode 100644
index 6847ae5..0000000
--- a/subprojects/fmt.wrap
+++ /dev/null
@@ -1,3 +0,0 @@
-[wrap-git]
-url = https://github.com/fmtlib/fmt
-revision = HEAD
diff --git a/test/meson.build b/test/meson.build
index d06a326..60cd774 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -36,7 +36,6 @@
gmock_dep,
dump,
phosphor_logging_dep,
- fmt_dep,
]),
workdir: meson.current_source_dir())
endforeach
diff --git a/watch.cpp b/watch.cpp
index fcf46bd..37a0b6a 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -2,9 +2,8 @@
#include "xyz/openbmc_project/Common/error.hpp"
-#include <fmt/core.h>
-
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace phosphor
{
@@ -35,9 +34,8 @@
// Check if watch DIR exists.
if (!std::filesystem::is_directory(path))
{
- log<level::ERR>(
- fmt::format("Watch directory doesn't exist, DIR({})", path.c_str())
- .c_str());
+ lg2::error("Watch directory doesn't exist, DIR: {DIRECTORY}",
+ "DIRECTORY", path);
elog<InternalFailure>();
}
@@ -45,11 +43,9 @@
if (-1 == wd)
{
auto error = errno;
- log<level::ERR>(
- fmt::format(
- "Error occurred during the inotify_add_watch call, errno({})",
- error)
- .c_str());
+ lg2::error(
+ "Error occurred during the inotify_add_watch call, errno: {ERRNO}",
+ "ERRNO", error);
elog<InternalFailure>();
}
@@ -58,10 +54,8 @@
if (0 > rc)
{
// Failed to add to event loop
- log<level::ERR>(
- fmt::format(
- "Error occurred during the sd_event_add_io call, rc({})", rc)
- .c_str());
+ lg2::error("Error occurred during the sd_event_add_io call, rc: {RC}",
+ "RC", rc);
elog<InternalFailure>();
}
}
@@ -73,10 +67,8 @@
if (-1 == fd)
{
auto error = errno;
- log<level::ERR>(
- fmt::format("Error occurred during the inotify_init1, errno({})",
- error)
- .c_str());
+ lg2::error("Error occurred during the inotify_init1, errno: {ERRNO}",
+ "ERRNO", error);
elog<InternalFailure>();
}
@@ -102,9 +94,8 @@
// Failed to read inotify event
// Report error and return
auto error = errno;
- log<level::ERR>(
- fmt::format("Error occurred during the read, errno({})", error)
- .c_str());
+ lg2::error("Error occurred during the read, errno: {ERRNO}", "ERRNO",
+ error);
report<InternalFailure>();
return 0;
}