Convert from log() to lg2()
Convert from the old log() API to the new lg2() API for logging journal
messages. The new API is simpler to use, and the old API may be
deprecated in the future.
Tested:
* Tested all lg2() calls to verify the resulting journal message was
correct.
* For the complete test plan, see
https://gist.github.com/smccarney/f4ed140bf7a46773b31c76b488e739dc
Change-Id: Ieb46c5d1481ceb51e5b0d51392b1c32596d8eac8
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/src/item_updater.cpp b/src/item_updater.cpp
index 44612b3..aea02ee 100644
--- a/src/item_updater.cpp
+++ b/src/item_updater.cpp
@@ -5,7 +5,7 @@
#include "utils.hpp"
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <cassert>
@@ -92,8 +92,8 @@
auto pos = path.rfind('/');
if (pos == std::string::npos)
{
- log<level::ERR>("No version id found in object path",
- entry("OBJPATH=%s", path.c_str()));
+ lg2::error("No version id found in object path {OBJPATH}", "OBJPATH",
+ path);
return;
}
@@ -131,10 +131,9 @@
auto it = versions.find(versionId);
if (it == versions.end())
{
- log<level::ERR>(("Error: Failed to find version " + versionId +
- " in item updater versions map."
- " Unable to remove.")
- .c_str());
+ lg2::error("Error: Failed to find version {VERSION_ID} in "
+ "item updater versions map. Unable to remove.",
+ "VERSION_ID", versionId);
}
else
{
@@ -146,10 +145,9 @@
auto ita = activations.find(versionId);
if (ita == activations.end())
{
- log<level::ERR>(("Error: Failed to find version " + versionId +
- " in item updater activations map."
- " Unable to remove.")
- .c_str());
+ lg2::error("Error: Failed to find version {VERSION_ID} in "
+ "item updater activations map. Unable to remove.",
+ "VERSION_ID", versionId);
}
else
{
@@ -270,8 +268,8 @@
auto it = psuPathActivationMap.find(psuInventoryPath);
if (it == psuPathActivationMap.end())
{
- log<level::ERR>("No Activation found for PSU",
- entry("PSUPATH=%s", psuInventoryPath.c_str()));
+ lg2::error("No Activation found for PSU {PSUPATH}", "PSUPATH",
+ psuInventoryPath);
return;
}
const auto& activationPtr = it->second;
@@ -386,11 +384,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format(
- "Unable to handle inventory PropertiesChanged event: {}",
- e.what())
- .c_str());
+ lg2::error(
+ "Unable to handle inventory PropertiesChanged event: {ERROR}",
+ "ERROR", e);
}
}
@@ -443,8 +439,7 @@
}
if (!fs::is_directory(dir))
{
- log<level::ERR>("The path is not a directory",
- entry("PATH=%s", dir.c_str()));
+ lg2::error("The path is not a directory: {PATH}", "PATH", dir);
return;
}
@@ -459,21 +454,19 @@
}
if (path == dir)
{
- log<level::ERR>("Model directory not found");
+ lg2::error("Model directory not found");
return;
}
if (!fs::is_directory(path))
{
- log<level::ERR>("The path is not a directory",
- entry("PATH=%s", path.c_str()));
+ lg2::error("The path is not a directory: {PATH}", "PATH", path);
return;
}
if (!fs::exists(manifest))
{
- log<level::ERR>("No MANIFEST found",
- entry("PATH=%s", manifest.c_str()));
+ lg2::error("No MANIFEST found at {PATH}", "PATH", manifest);
return;
}
// If the model in manifest does not match the dir name
@@ -488,8 +481,8 @@
auto model = info["model"];
if (path.stem() != model)
{
- log<level::ERR>("Unmatched model", entry("PATH=%s", path.c_str()),
- entry("MODEL=%s", model.c_str()));
+ lg2::error("Unmatched model: path={PATH}, model={MODEL}", "PATH",
+ path, "MODEL", model);
}
else
{
@@ -520,8 +513,7 @@
}
else
{
- log<level::ERR>("MANIFEST is not a file",
- entry("PATH=%s", manifest.c_str()));
+ lg2::error("MANIFEST is not a file: {PATH}", "PATH", manifest);
}
}
@@ -576,9 +568,8 @@
{
if (!utils::isAssociated(p, assocs))
{
- log<level::INFO>(
- "Automatically update PSU",
- entry("VERSION_ID=%s", latestVersionId->c_str()));
+ lg2::info("Automatically update PSUs to version {VERSION_ID}",
+ "VERSION_ID", *latestVersionId);
invokeActivation(activation);
break;
}
@@ -632,10 +623,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- std::format("Unable to handle inventory InterfacesAdded event: {}",
- e.what())
- .c_str());
+ lg2::error("Unable to handle inventory InterfacesAdded event: {ERROR}",
+ "ERROR", e);
}
}