logging: switch to lg2
It is recommended to use `phosphor::lg2` to format log, and the
correct `CODE_LINE` and `CODE_FUNC` values can be used in log
tracking.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ic8a400451f96cde5bdb9f47094806bd31adce7d9
diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp
index 7eeee32..5889ed3 100644
--- a/bmc_epoch.cpp
+++ b/bmc_epoch.cpp
@@ -7,7 +7,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
// Need to do this since its not exported outside of the kernel.
@@ -47,8 +47,7 @@
timeFd = timerfd_create(CLOCK_REALTIME, 0);
if (timeFd == -1)
{
- log<level::ERR>("Failed to create timerfd", entry("ERRNO=%d", errno),
- entry("ERR=%s", strerror(errno)));
+ lg2::error("Failed to create timerfd: {ERRNO}", "ERRNO", errno);
elog<InternalFailure>();
}
@@ -56,8 +55,7 @@
timeFd, TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET, &maxTime, nullptr);
if (r != 0)
{
- log<level::ERR>("Failed to set timerfd", entry("ERRNO=%d", errno),
- entry("ERR=%s", strerror(errno)));
+ lg2::error("Failed to set timerfd: {ERRNO}", "ERRNO", errno);
elog<InternalFailure>();
}
@@ -66,8 +64,7 @@
this);
if (r < 0)
{
- log<level::ERR>("Failed to add event", entry("ERRNO=%d", -r),
- entry("ERR=%s", strerror(-r)));
+ lg2::error("Failed to add event: {ERRNO}", "ERRNO", errno);
elog<InternalFailure>();
}
timeChangeEventSource.reset(es);
diff --git a/epoch_base.cpp b/epoch_base.cpp
index 8f51f41..a336573 100644
--- a/epoch_base.cpp
+++ b/epoch_base.cpp
@@ -2,7 +2,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Time/error.hpp>
#include <iomanip>
@@ -48,7 +48,7 @@
}
catch (const sdbusplus::exception::exception& ex)
{
- log<level::ERR>("Error in setting system time");
+ lg2::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 383d416..ceaed7e 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -6,7 +6,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
namespace rules = sdbusplus::bus::match::rules;
@@ -84,12 +84,11 @@
try
{
bus.call_noreply(method);
- log<level::INFO>("Updated NTP setting", entry("ENABLED=%d", isNtp));
+ lg2::info("Updated NTP setting: {ENABLED}", "ENABLED", isNtp);
}
catch (const sdbusplus::exception::exception& ex)
{
- log<level::ERR>("Failed to update NTP setting",
- entry("ERR=%s", ex.what()));
+ lg2::error("Failed to update NTP setting: {ERROR}", "ERROR", ex);
}
}
@@ -98,8 +97,7 @@
auto newMode = utils::strToMode(mode);
if (newMode != timeMode)
{
- log<level::INFO>("Time mode is changed",
- entry("MODE=%s", mode.c_str()));
+ lg2::info("Time mode has been changed to {MODE}", "MODE", newMode);
timeMode = newMode;
return true;
}
diff --git a/settings.cpp b/settings.cpp
index c136c22..1ac0d9e 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -3,7 +3,7 @@
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace settings
{
@@ -38,12 +38,12 @@
}
catch (const sdbusplus::exception::exception& ex)
{
- log<level::ERR>("Failed to invoke GetSubTree method");
+ lg2::error("Failed to invoke GetSubTree method: {ERROR}", "ERROR", ex);
}
if (result.empty())
{
- log<level::ERR>("Invalid response from mapper");
+ lg2::error("Invalid response from mapper");
elog<InternalFailure>();
}
@@ -79,12 +79,12 @@
}
catch (const sdbusplus::exception::exception& ex)
{
- log<level::ERR>("Error in mapper GetObject");
+ lg2::error("Error in mapper GetObject: {ERROR}", "ERROR", ex);
}
if (result.empty())
{
- log<level::ERR>("Invalid response from mapper");
+ lg2::error("Invalid response from mapper");
elog<InternalFailure>();
}
diff --git a/utils.cpp b/utils.cpp
index c9a8fbc..be29c74 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -1,7 +1,5 @@
#include "utils.hpp"
-#include <phosphor-logging/log.hpp>
-
namespace phosphor
{
namespace time
@@ -17,8 +15,6 @@
namespace utils
{
-using namespace phosphor::logging;
-
std::string getService(sdbusplus::bus::bus& bus, const char* path,
const char* interface)
{
@@ -35,7 +31,7 @@
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
- log<level::ERR>("Error reading mapper response");
+ lg2::error("Error reading mapper response");
throw std::runtime_error("Error reading mapper response");
}
if (mapperResponse.size() < 1)
@@ -46,9 +42,9 @@
}
catch (const sdbusplus::exception::exception& ex)
{
- log<level::ERR>("Mapper call failed", entry("METHOD=%d", "GetObject"),
- entry("PATH=%s", path),
- entry("INTERFACE=%s", interface));
+ lg2::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 af83d38..9639cbf 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -2,7 +2,7 @@
#include "types.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
namespace phosphor
@@ -12,8 +12,6 @@
namespace utils
{
-using namespace phosphor::logging;
-
/** @brief The template function to get property from the requested dbus path
*
* @param[in] bus - The Dbus bus object
@@ -40,9 +38,10 @@
}
catch (const sdbusplus::exception::exception& ex)
{
- log<level::ERR>("GetProperty call failed", entry("PATH=%s", path),
- entry("INTERFACE=%s", interface),
- entry("PROPERTY=%s", propertyName));
+ lg2::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");
}
}