ipmid: switch to lg2
Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I838587b2d564f3c00b78ce37e175d7e8ace51142
diff --git a/include/ipmid/handler.hpp b/include/ipmid/handler.hpp
index 62fcbe9..77f6670 100644
--- a/include/ipmid/handler.hpp
+++ b/include/ipmid/handler.hpp
@@ -20,6 +20,7 @@
#include <boost/callable_traits.hpp>
#include <ipmid/api-types.hpp>
#include <ipmid/message.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <user_channel/channel_layer.hpp>
@@ -266,21 +267,18 @@
}
catch (const HandlerException& e)
{
- phosphor::logging::log<phosphor::logging::level::INFO>(
- "Handler produced exception",
- phosphor::logging::entry("CC=%x", e.code()),
- phosphor::logging::entry("EXCEPTION=%s", e.what()),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::info("Handler produced exception, NetFn: {NETFN}, "
+ "Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", e);
return errorResponse(request, e.code());
}
catch (const std::exception& e)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Handler failed to catch exception",
- phosphor::logging::entry("EXCEPTION=%s", e.what()),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::error("Handler failed to catch exception, NetFn: {NETFN}, "
+ "Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", e);
return errorResponse(request, ccUnspecifiedError);
}
catch (const HandlerCompletion& c)
@@ -290,11 +288,10 @@
catch (...)
{
const char* what = currentExceptionType();
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Handler failed to catch exception",
- phosphor::logging::entry("EXCEPTION=%s", what),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::error("Handler failed to catch exception, NetFn: {NETFN}, "
+ "Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", what);
return errorResponse(request, ccUnspecifiedError);
}
@@ -367,21 +364,18 @@
}
catch (const HandlerException& e)
{
- phosphor::logging::log<phosphor::logging::level::INFO>(
- "Legacy Handler produced exception",
- phosphor::logging::entry("CC=%x", e.code()),
- phosphor::logging::entry("EXCEPTION=%s", e.what()),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::info("Legacy Handler produced exception, NetFn: {NETFN}, "
+ "Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", e);
return errorResponse(request, e.code());
}
catch (const std::exception& e)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Legacy Handler failed to catch exception",
- phosphor::logging::entry("EXCEPTION=%s", e.what()),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::error("Legacy Handler failed to catch exception, "
+ "NetFn: {NETFN}, Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", e);
return errorResponse(request, ccUnspecifiedError);
}
catch (const HandlerCompletion& c)
@@ -391,11 +385,10 @@
catch (...)
{
const char* what = currentExceptionType();
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Handler failed to catch exception",
- phosphor::logging::entry("EXCEPTION=%s", what),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::error("Handler failed to catch exception, NetFn: {NETFN}, "
+ "Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", what);
return errorResponse(request, ccUnspecifiedError);
}
response->cc = ccRet;
@@ -457,21 +450,18 @@
}
catch (const HandlerException& e)
{
- phosphor::logging::log<phosphor::logging::level::INFO>(
- "Legacy OEM Handler produced exception",
- phosphor::logging::entry("CC=%x", e.code()),
- phosphor::logging::entry("EXCEPTION=%s", e.what()),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::info("Legacy OEM Handler produced exception, NetFn: {NETFN}, "
+ "Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", e);
return errorResponse(request, e.code());
}
catch (const std::exception& e)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Legacy OEM Handler failed to catch exception",
- phosphor::logging::entry("EXCEPTION=%s", e.what()),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::error("Legacy OEM Handler failed to catch exception, "
+ "NetFn: {NETFN}, Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", e);
return errorResponse(request, ccUnspecifiedError);
}
catch (const HandlerCompletion& c)
@@ -481,11 +471,10 @@
catch (...)
{
const char* what = currentExceptionType();
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Handler failed to catch exception",
- phosphor::logging::entry("EXCEPTION=%s", what),
- phosphor::logging::entry("NETFN=%x", request->ctx->netFn),
- phosphor::logging::entry("CMD=%x", request->ctx->cmd));
+ lg2::error("Legacy failed to catch exception, NetFn: {NETFN}, "
+ "Cmd: {CMD}: {ERROR}",
+ "NETFN", lg2::hex, request->ctx->netFn, "CMD", lg2::hex,
+ request->ctx->cmd, "ERROR", what);
return errorResponse(request, ccUnspecifiedError);
}
response->cc = ccRet;
diff --git a/include/ipmid/message.hpp b/include/ipmid/message.hpp
index 5264112..7a709e4 100644
--- a/include/ipmid/message.hpp
+++ b/include/ipmid/message.hpp
@@ -19,7 +19,7 @@
#include <ipmid/api-types.hpp>
#include <ipmid/message/types.hpp>
#include <ipmid/types.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <algorithm>
@@ -119,11 +119,12 @@
~Payload()
{
- using namespace phosphor::logging;
if (raw.size() != 0 && std::uncaught_exceptions() == 0 && !trailingOk &&
!unpackCheck && !unpackError)
{
- log<level::ERR>("Failed to check request for full unpack");
+ lg2::error(
+ "Failed to check request for full unpack: raw size: {RAW_SIZE}",
+ "RAW_SIZE", raw.size());
}
}
diff --git a/include/ipmid/message/pack.hpp b/include/ipmid/message/pack.hpp
index 5ca94b6..407c35f 100644
--- a/include/ipmid/message/pack.hpp
+++ b/include/ipmid/message/pack.hpp
@@ -16,6 +16,7 @@
#pragma once
#include <ipmid/message/types.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <phosphor-logging/log.hpp>
#include <array>
@@ -120,8 +121,7 @@
uint8_t len;
if (t.length() > std::numeric_limits<decltype(len)>::max())
{
- using namespace phosphor::logging;
- log<level::ERR>("long string truncated on IPMI message pack");
+ lg2::error("long string truncated on IPMI message pack");
return 1;
}
len = static_cast<uint8_t>(t.length());
diff --git a/libipmid/signals.cpp b/libipmid/signals.cpp
index 4ac5685..5eca6ad 100644
--- a/libipmid/signals.cpp
+++ b/libipmid/signals.cpp
@@ -1,13 +1,11 @@
#include <boost/asio/signal_set.hpp>
#include <ipmid/api.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <forward_list>
#include <memory>
#include <vector>
-using namespace phosphor::logging;
-
namespace
{
@@ -49,9 +47,9 @@
{
if (ec)
{
- log<level::ERR>("Error in common signal handler",
- entry("SIGNAL=%d", sigNum),
- entry("ERROR=%s", ec.message().c_str()));
+ lg2::error("Error in common signal handler, "
+ "signal: {SIGNAL}, error: {ERROR}",
+ "SIGNAL", sigNum, "ERROR", ec.message());
return;
}
for (auto h = handlers.begin(); h != handlers.end(); h++)
diff --git a/libipmid/utils.cpp b/libipmid/utils.cpp
index fb96ea6..09b152b 100644
--- a/libipmid/utils.cpp
+++ b/libipmid/utils.cpp
@@ -10,7 +10,7 @@
#include <ipmid/utils.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/message/types.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -49,8 +49,8 @@
ObjectTree objectTree = getSubTree(bus, interfaces, serviceRoot);
if (objectTree.empty())
{
- log<level::ERR>("No Object has implemented the interface",
- entry("INTERFACE=%s", interface.c_str()));
+ lg2::error("No Object has implemented the interface: {INTERFACE}",
+ "INTERFACE", interface);
elog<InternalFailure>();
}
@@ -73,8 +73,8 @@
if (found == objectTree.end())
{
- log<level::ERR>("Failed to find object which matches",
- entry("MATCH=%s", match.c_str()));
+ lg2::error("Failed to find object which matches: {MATCH}", "MATCH",
+ match);
elog<InternalFailure>();
// elog<> throws an exception.
}
@@ -145,10 +145,10 @@
if (!bus.call(method, timeout.count()))
{
- log<level::ERR>("Failed to set property",
- entry("PROPERTY=%s", property.c_str()),
- entry("PATH=%s", objPath.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ lg2::error("Failed to set {PROPERTY}, path: {PATH}, "
+ "interface: {INTERFACE}",
+ "PROPERTY", property, "PATH", objPath, "INTERFACE",
+ interface);
elog<InternalFailure>();
}
}
@@ -270,10 +270,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::INFO>("sdbusplus exception - Unable to delete the objects",
- entry("ERROR=%s", e.what()),
- entry("INTERFACE=%s", interface.c_str()),
- entry("SERVICE=%s", serviceRoot.c_str()));
+ lg2::info("sdbusplus exception - Unable to delete the objects, "
+ "service: {SERVICE}, interface: {INTERFACE}, error: {ERROR}",
+ "SERVICE", serviceRoot, "INTERFACE", interface, "ERROR", e);
}
}
@@ -300,10 +299,9 @@
if (objectTree.empty())
{
- log<level::ERR>(
- "No Object has implemented the interface",
- entry("PATH=%s", path.c_str()),
- entry("INTERFACES=%s", convertToString(interfaces).c_str()));
+ lg2::error("No Object has implemented the interface: {INTERFACE}, "
+ "path: {PATH}",
+ "INTERFACE", convertToString(interfaces), "PATH", path);
elog<InternalFailure>();
}
@@ -378,10 +376,10 @@
if (objectTree.empty())
{
- log<level::ERR>("No Object has implemented the interface",
- entry("INTERFACE=%s", interface.c_str()),
- entry("NETFN=%x", ctx->netFn),
- entry("CMD=%x,", ctx->cmd));
+ lg2::error("No Object has implemented the interface: {INTERFACE}, "
+ "NetFn: {NETFN}, Cmd: {CMD}",
+ "INTERFACE", interface, "NETFN", lg2::hex, ctx->netFn, "CMD",
+ lg2::hex, ctx->cmd);
return boost::system::errc::make_error_code(
boost::system::errc::no_such_process);
}
@@ -403,10 +401,10 @@
if (found == objectTree.end())
{
- log<level::ERR>("Failed to find object which matches",
- entry("MATCH=%s", match.c_str()),
- entry("NETFN=%x", ctx->netFn),
- entry("CMD=%x,", ctx->cmd));
+ lg2::error("Failed to find object which matches: {MATCH}, "
+ "NetFn: {NETFN}, Cmd: {CMD}",
+ "MATCH", match, "NETFN", lg2::hex, ctx->netFn, "CMD",
+ lg2::hex, ctx->cmd);
// set ec
return boost::system::errc::make_error_code(
boost::system::errc::no_such_file_or_directory);
@@ -490,12 +488,12 @@
DELETE_INTERFACE, "Delete");
if (ec)
{
- log<level::ERR>("Failed to delete all objects",
- entry("INTERFACE=%s", interface.c_str()),
- entry("SERVICE=%s", serviceRoot.c_str()),
- entry("NETFN=%x", ctx->netFn),
- entry("CMD=%x,", ctx->cmd),
- entry("ERROR=%s", ec.message().c_str()));
+ lg2::error("Failed to delete all objects, service: {SERVICE}, "
+ "interface: {INTERFACE}, NetFn: {NETFN}, "
+ "Cmd: {CMD}, Error: {ERROR}",
+ "SERVICE", serviceRoot, "INTERFACE", interface, "NETFN",
+ lg2::hex, ctx->netFn, "CMD", lg2::hex, ctx->cmd, "ERROR",
+ ec.message());
break;
}
}
@@ -531,9 +529,9 @@
if (objectTree.empty())
{
- log<level::ERR>("No Object has implemented the interface",
- entry("PATH=%s", path.c_str()),
- entry("INTERFACES=%s", interfaceList.c_str()));
+ lg2::error("No Object has implemented the interface: {INTERFACE}, "
+ "path: {PATH}",
+ "INTERFACE", interfaceList, "PATH", path);
elog<InternalFailure>();
}
@@ -560,8 +558,7 @@
int i2cDev = ::open(i2cBus.c_str(), O_RDWR | O_CLOEXEC);
if (i2cDev < 0)
{
- log<level::ERR>("Failed to open i2c bus",
- phosphor::logging::entry("BUS=%s", i2cBus.c_str()));
+ lg2::error("Failed to open i2c bus: {BUS}", "BUS", i2cBus);
return ipmi::ccInvalidFieldRequest;
}
@@ -598,8 +595,7 @@
if (ret < 0)
{
- log<level::ERR>("I2C WR Failed!",
- phosphor::logging::entry("RET=%d", ret));
+ lg2::error("I2C WR Failed! {RET}", "RET", ret);
return ipmi::ccUnspecifiedError;
}
if (readCount)
diff --git a/test/meson.build b/test/meson.build
index b2b9929..607c873 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -57,6 +57,7 @@
'message/unpack.cpp',
include_directories: root_inc,
build_by_default: false,
+ override_options: ['b_lundef=true'],
implicit_include_directories: false,
dependencies: [boost, phosphor_logging_dep, crypto, systemd, sdbusplus_dep, gtest, gmock]
))
diff --git a/test/message/payload.cpp b/test/message/payload.cpp
index 0114e11..38977e4 100644
--- a/test/message/payload.cpp
+++ b/test/message/payload.cpp
@@ -317,16 +317,9 @@
extern "C"
{
-int sd_journal_send(const char* format, ...)
+int sd_journal_sendv(const struct iovec* iov, int /* n */)
{
- logs.push_back(format);
- return 0;
-}
-
-int sd_journal_send_with_location(const char* /*file*/, const char* /*line*/,
- const char* /*func*/, const char* format, ...)
-{
- logs.push_back(format);
+ logs.push_back(std::string((char*)iov[0].iov_base, iov[0].iov_len));
return 0;
}
}