Minor changes in the code
- fix a typo in README and wrap file.
- refactoring lg2 errorlog usage.
Change-Id: I3b55b86a505405f02fe70429a266c467b87b17ff
Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
diff --git a/README.md b/README.md
index 42e14af..f4d0b87 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
```
meson builddir -Dbuildtype=minsize -Dtests=disabled
- ninja -C buildir
+ ninja -C builddir
```
* Generate test coverage report:
diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp
index db4051a..aa05060 100644
--- a/bmc_epoch.cpp
+++ b/bmc_epoch.cpp
@@ -32,6 +32,8 @@
constexpr auto METHOD_SET_TIME = "SetTime";
} // namespace
+PHOSPHOR_LOG2_USING;
+
namespace server = sdbusplus::xyz::openbmc_project::Time::server;
using namespace phosphor::logging;
using FailedError = sdbusplus::xyz::openbmc_project::Time::Error::Failed;
@@ -51,7 +53,7 @@
timeFd = timerfd_create(CLOCK_REALTIME, 0);
if (timeFd == -1)
{
- lg2::error("Failed to create timerfd: {ERRNO}", "ERRNO", errno);
+ error("Failed to create timerfd: {ERRNO}", "ERRNO", errno);
elog<InternalFailure>();
}
@@ -59,7 +61,7 @@
timeFd, TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &maxTime, nullptr);
if (r != 0)
{
- lg2::error("Failed to set timerfd: {ERRNO}", "ERRNO", errno);
+ error("Failed to set timerfd: {ERRNO}", "ERRNO", errno);
elog<InternalFailure>();
}
@@ -68,7 +70,7 @@
this);
if (r < 0)
{
- lg2::error("Failed to add event: {ERRNO}", "ERRNO", errno);
+ error("Failed to add event: {ERRNO}", "ERRNO", errno);
elog<InternalFailure>();
}
timeChangeEventSource.reset(es);
@@ -131,7 +133,7 @@
}
catch (const sdbusplus::exception_t& ex)
{
- lg2::error("Error in setting system time: {ERROR}", "ERROR", ex);
+ error("Error in setting system time: {ERROR}", "ERROR", ex);
using namespace xyz::openbmc_project::Time;
elog<FailedError>(Failed::REASON(ex.what()));
}
diff --git a/manager.cpp b/manager.cpp
index 88406f4..169fb30 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -22,6 +22,8 @@
namespace time
{
+PHOSPHOR_LOG2_USING;
+
Manager::Manager(sdbusplus::bus_t& bus) : bus(bus), settings(bus)
{
using namespace sdbusplus::bus::match::rules;
@@ -79,11 +81,11 @@
// 'false' meaning no policy-kit
bus.call_noreply(method);
- lg2::info("Updated NTP setting: {ENABLED}", "ENABLED", isNtp);
+ info("Updated NTP setting: {ENABLED}", "ENABLED", isNtp);
}
catch (const sdbusplus::exception_t& ex)
{
- lg2::error("Failed to update NTP setting: {ERROR}", "ERROR", ex);
+ error("Failed to update NTP setting: {ERROR}", "ERROR", ex);
}
}
@@ -94,14 +96,14 @@
auto newMode = utils::strToMode(mode);
if (newMode != timeMode)
{
- lg2::info("Time mode has been changed to {MODE}", "MODE", newMode);
+ info("Time mode has been changed to {MODE}", "MODE", newMode);
timeMode = newMode;
return true;
}
}
catch (const sdbusplus::exception_t& ex)
{
- lg2::error("Failed to convert mode from string: {ERROR}", "ERROR", ex);
+ error("Failed to convert mode from string: {ERROR}", "ERROR", ex);
}
return false;
@@ -124,7 +126,7 @@
}
catch (const std::exception& ex)
{
- lg2::error(
+ error(
"Failed to get property: {ERROR}, path: {PATH}, interface: {INTERFACE}, name: {NAME}",
"ERROR", ex, "PATH", path, "INTERFACE", interface, "NAME", setting);
return {};
diff --git a/settings.cpp b/settings.cpp
index 50081b7..d0d5026 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -8,6 +8,8 @@
namespace settings
{
+PHOSPHOR_LOG2_USING;
+
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
@@ -26,12 +28,12 @@
}
catch (const sdbusplus::exception_t& ex)
{
- lg2::error("Failed to invoke GetSubTree method: {ERROR}", "ERROR", ex);
+ error("Failed to invoke GetSubTree method: {ERROR}", "ERROR", ex);
}
if (result.empty())
{
- lg2::error("Invalid response from mapper");
+ error("Invalid response from mapper");
}
for (const auto& iter : result)
@@ -49,5 +51,4 @@
}
}
}
-
} // namespace settings
diff --git a/utils.cpp b/utils.cpp
index bc95feb..f0b8704 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -15,6 +15,8 @@
namespace utils
{
+PHOSPHOR_LOG2_USING;
+
std::string getService(sdbusplus::bus_t& bus, const char* path,
const char* interface)
{
@@ -31,7 +33,7 @@
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
- lg2::error("Error reading mapper response");
+ error("Error reading mapper response");
throw std::runtime_error("Error reading mapper response");
}
@@ -39,7 +41,7 @@
}
catch (const sdbusplus::exception_t& ex)
{
- lg2::error(
+ error(
"Mapper call failed: path:{PATH}, interface:{INTF}, error:{ERROR}",
"PATH", path, "INTF", interface, "ERROR", ex);
throw std::runtime_error("Mapper call failed");
diff --git a/utils.hpp b/utils.hpp
index dd81314..34a67e8 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -5,6 +5,7 @@
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
+#include <string_view>
#include <vector>
namespace phosphor
@@ -21,6 +22,8 @@
using MapperResponse =
std::vector<std::pair<Path, std::vector<std::pair<Service, Interfaces>>>>;
+PHOSPHOR_LOG2_USING;
+
/** @brief The template function to get property from the requested dbus path
*
* @param[in] bus - The Dbus bus object
@@ -47,10 +50,10 @@
}
catch (const sdbusplus::exception_t& ex)
{
- lg2::error("GetProperty call failed, path:{PATH}, interface:{INTF}, "
- "propertyName:{NAME}, error:{ERROR}",
- "PATH", path, "INTF", interface, "NAME", propertyName,
- "ERROR", ex);
+ error("GetProperty call failed, path:{PATH}, interface:{INTF}, "
+ "propertyName:{NAME}, error:{ERROR}",
+ "PATH", path, "INTF", interface, "NAME", propertyName, "ERROR",
+ ex);
throw std::runtime_error("GetProperty call failed");
}
}