logging: switch to lg2
After switching to C++20, 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: I4aabaafe997e13c10d655a83a9ef0071ad11126e
diff --git a/auth_algo.cpp b/auth_algo.cpp
index 4572831..40d277f 100644
--- a/auth_algo.cpp
+++ b/auth_algo.cpp
@@ -1,12 +1,12 @@
#include "auth_algo.hpp"
+#include <error.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/sha.h>
+#include <string.h>
-#include <phosphor-logging/log.hpp>
-
-using namespace phosphor::logging;
+#include <phosphor-logging/lg2.hpp>
namespace cipher
{
@@ -25,7 +25,7 @@
if (HMAC(EVP_sha1(), userKey.data(), userKey.size(), input.data(),
input.size(), output.data(), &mdLen) == NULL)
{
- log<level::ERR>("Generate HMAC failed");
+ lg2::error("Generate HMAC failed: {ERROR}", "ERROR", strerror(errno));
output.resize(0);
}
@@ -41,7 +41,8 @@
if (HMAC(EVP_sha1(), sessionIntegrityKey.data(), SHA_DIGEST_LENGTH,
input.data(), input.size(), output.data(), &mdLen) == NULL)
{
- log<level::ERR>("Generate Session Integrity Key failed");
+ lg2::error("Generate Session Integrity Key failed: {ERROR}", "ERROR",
+ strerror(errno));
output.resize(0);
}
output.resize(integrityCheckValueLength);
@@ -58,7 +59,8 @@
if (HMAC(EVP_sha256(), userKey.data(), userKey.size(), input.data(),
input.size(), output.data(), &mdLen) == NULL)
{
- log<level::ERR>("Generate HMAC_SHA256 failed");
+ lg2::error("Generate HMAC_SHA256 failed: {ERROR}", "ERROR",
+ strerror(errno));
output.resize(0);
}
@@ -75,8 +77,9 @@
sessionIntegrityKey.size(), input.data(), input.size(),
output.data(), &mdLen) == NULL)
{
- log<level::ERR>(
- "Generate HMAC_SHA256_128 Integrity Check Value failed");
+ lg2::error(
+ "Generate HMAC_SHA256_128 Integrity Check Value failed: {ERROR}",
+ "ERROR", strerror(errno));
output.resize(0);
}
output.resize(integrityCheckValueLength);
diff --git a/command/channel_auth.cpp b/command/channel_auth.cpp
index 8368412..44d5cad 100644
--- a/command/channel_auth.cpp
+++ b/command/channel_auth.cpp
@@ -1,12 +1,13 @@
#include "channel_auth.hpp"
+#include <errno.h>
#include <ipmid/api.h>
#include <ipmid/types.hpp>
#include <ipmid/utils.hpp>
#include <nlohmann/json.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <user_channel/channel_layer.hpp>
#include <user_channel/user_layer.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -120,14 +121,16 @@
std::ifstream jsonFile(configFile);
if (!jsonFile.is_open())
{
- log<level::ERR>("Channel Cipher suites file not found");
+ lg2::error("Channel Cipher suites file not found: {ERROR}", "ERROR",
+ strerror(errno));
elog<InternalFailure>();
}
auto data = Json::parse(jsonFile, nullptr, false);
if (data.is_discarded())
{
- log<level::ERR>("Parsing channel cipher suites JSON failed");
+ lg2::error("Parsing channel cipher suites JSON failed: {ERROR}",
+ "ERROR", strerror(errno));
elog<InternalFailure>();
}
@@ -231,7 +234,8 @@
}
if (!ipmi::isValidPayloadType(static_cast<ipmi::PayloadType>(payloadType)))
{
- log<level::DEBUG>("Get channel cipher suites - Invalid payload type");
+ lg2::debug("Get channel cipher suites - Invalid payload type: {ERROR}",
+ "ERROR", strerror(errno));
constexpr uint8_t ccPayloadTypeNotSupported = 0x80;
return errorResponse(ccPayloadTypeNotSupported);
}
@@ -258,7 +262,8 @@
ipmi::EChannelSessSupported::none) ||
!(ipmi::doesDeviceExist(rspChannel)))
{
- log<level::DEBUG>("Get channel cipher suites - Device does not exist");
+ lg2::debug("Get channel cipher suites - Device does not exist:{ERROR}",
+ "ERROR", strerror(errno));
return errorResponse(IPMI_CC_INVALID_FIELD_REQUEST);
}
diff --git a/command/guid.cpp b/command/guid.cpp
index 56b459f..253a2dc 100644
--- a/command/guid.cpp
+++ b/command/guid.cpp
@@ -3,7 +3,7 @@
#include <ipmid/api.h>
#include <mapper.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sstream>
#include <string>
@@ -45,9 +45,8 @@
int rc = mapper_get_service(bus, guidObjPath, &busname);
if (rc < 0)
{
- log<level::ERR>("Failed to get bus name",
- entry("PATH=%s", guidObjPath),
- entry("ERROR=%s", strerror(-rc)));
+ lg2::error("Failed to get bus name, path: {PATH}, error: {ERROR}",
+ "PATH", guidObjPath, "ERROR", strerror(-rc));
break;
}
@@ -55,16 +54,16 @@
&error, &reply, "ss", chassisIntf, "uuid");
if (rc < 0)
{
- log<level::ERR>("Failed to call Get Method",
- entry("ERROR=%s", strerror(-rc)));
+ lg2::error("Failed to call Get Method: {ERROR}", "ERROR",
+ strerror(-rc));
break;
}
rc = sd_bus_message_read(reply, "v", "s", &uuid);
if (rc < 0 || uuid == NULL)
{
- log<level::ERR>("Failed to get a response",
- entry("ERROR=%s", strerror(-rc)));
+ lg2::error("Failed to get a response: {ERROR}", "ERROR",
+ strerror(-rc));
break;
}
diff --git a/command/open_session.cpp b/command/open_session.cpp
index 0d82a06..21e0f3f 100644
--- a/command/open_session.cpp
+++ b/command/open_session.cpp
@@ -4,9 +4,7 @@
#include "endian.hpp"
#include "sessions_manager.hpp"
-#include <phosphor-logging/log.hpp>
-
-using namespace phosphor::logging;
+#include <phosphor-logging/lg2.hpp>
namespace command
{
@@ -88,8 +86,8 @@
{
response->status_code =
static_cast<uint8_t>(RAKP_ReturnCode::INSUFFICIENT_RESOURCE);
- log<level::ERR>("openSession : Problem opening a session",
- entry("EXCEPTION=%s", e.what()));
+ lg2::error("openSession : Problem opening a session: {ERROR}", "ERROR",
+ e);
return outPayload;
}
diff --git a/command/payload_cmds.cpp b/command/payload_cmds.cpp
index 4083209..b3bcca2 100644
--- a/command/payload_cmds.cpp
+++ b/command/payload_cmds.cpp
@@ -7,7 +7,7 @@
#include <ipmid/api.h>
#include <ipmid/api-types.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace sol
{
@@ -15,8 +15,6 @@
namespace command
{
-using namespace phosphor::logging;
-
std::vector<uint8_t> activatePayload(const std::vector<uint8_t>& inPayload,
std::shared_ptr<message::Handler>& handler)
{
@@ -94,7 +92,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(e.what());
+ lg2::error("Failed to start SOL payload: {ERROR}", "ERROR", e);
response->completionCode = IPMI_CC_UNSPECIFIED_ERROR;
return outPayload;
}
@@ -161,7 +159,8 @@
}
catch (const std::exception& e)
{
- log<level::INFO>(e.what());
+ lg2::info("Failed to call the activating method: {ERROR}", "ERROR",
+ e);
/*
* In case session has been closed (like in the case of inactivity
* timeout), then activating function would throw an exception,
@@ -173,7 +172,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(e.what());
+ lg2::error("Failed to call the getContext method: {ERROR}", "ERROR", e);
response->completionCode = IPMI_CC_UNSPECIFIED_ERROR;
return outPayload;
}
diff --git a/command/rakp12.cpp b/command/rakp12.cpp
index a68cdcb..c72611e 100644
--- a/command/rakp12.cpp
+++ b/command/rakp12.cpp
@@ -8,14 +8,12 @@
#include <openssl/rand.h>
#include <ipmid/types.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
#include <cstring>
#include <iomanip>
-using namespace phosphor::logging;
-
namespace command
{
@@ -32,11 +30,10 @@
std::string messageID = "OpenBMC." +
std::string(openBMCMessageRegistryVersion) +
"InvalidLoginAttempted";
- phosphor::logging::log<phosphor::logging::level::ERR>(
- journalMsg.c_str(),
- phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", messageID.c_str()),
- phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s",
- messageArgs.value().c_str()));
+ lg2::error(
+ "message: {MSG}, id: {REDFISH_MESSAGE_ID}, args: {REDFISH_MESSAGE_ARGS}",
+ "MSG", journalMsg, "REDFISH_MESSAGE_ID", messageID,
+ "REDFISH_MESSAGE_ARGS", messageArgs.value());
}
std::vector<uint8_t> RAKP12(const std::vector<uint8_t>& inPayload,
std::shared_ptr<message::Handler>& /* handler */)
@@ -56,7 +53,7 @@
if (endian::from_ipmi(request->managedSystemSessionID) ==
session::sessionZero)
{
- log<level::INFO>("RAKP12: BMC invalid Session ID");
+ lg2::info("RAKP12: BMC invalid Session ID");
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID);
return outPayload;
@@ -70,8 +67,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("RAKP12 : session not found",
- entry("EXCEPTION=%s", e.what()));
+ lg2::error("RAKP12 : session not found: {ERROR}", "ERROR", e);
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID);
return outPayload;
@@ -211,8 +207,9 @@
// Check whether user is already locked for failed attempts
if (!ipmi::ipmiUserPamAuthenticate(userName, passwd))
{
- log<level::ERR>("Authentication failed - user already locked out",
- entry("USER-ID=%d", static_cast<uint8_t>(userId)));
+ lg2::error(
+ "Authentication failed - user already locked out, user id: {ID}",
+ "ID", userId);
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME);
@@ -234,8 +231,7 @@
}
if (!isChannelAccessModeEnabled(session->sessionChannelAccess.accessMode))
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Channel access mode disabled.");
+ lg2::error("Channel access mode disabled.");
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::INACTIVE_ROLE);
logInvalidLoginRedfishEvent(message);
@@ -274,8 +270,7 @@
((request->req_max_privilege_level & session::reqMaxPrivMask) !=
session->sessionUserPrivAccess.privilege))
{
- log<level::INFO>(
- "Username/Privilege lookup failed for requested privilege");
+ lg2::info("Username/Privilege lookup failed for requested privilege");
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::UNAUTH_NAME);
diff --git a/command/rakp34.cpp b/command/rakp34.cpp
index 626bc15..f14430e 100644
--- a/command/rakp34.cpp
+++ b/command/rakp34.cpp
@@ -6,13 +6,11 @@
#include "rmcp.hpp"
#include "sessions_manager.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <algorithm>
#include <cstring>
-using namespace phosphor::logging;
-
namespace command
{
@@ -75,7 +73,7 @@
// Check if the RAKP3 Payload Length is as expected
if (inPayload.size() < sizeof(RAKP3request))
{
- log<level::INFO>("RAKP34: Invalid RAKP3 request");
+ lg2::info("RAKP34: Invalid RAKP3 request");
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::INVALID_INTEGRITY_VALUE);
return outPayload;
@@ -85,7 +83,7 @@
if (endian::from_ipmi(request->managedSystemSessionID) ==
session::sessionZero)
{
- log<level::INFO>("RAKP34: BMC invalid Session ID");
+ lg2::info("RAKP34: BMC invalid Session ID");
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID);
return outPayload;
@@ -99,8 +97,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("RAKP12 : session not found",
- entry("EXCEPTION=%s", e.what()));
+ lg2::error("RAKP12 : session not found: {ERROR}", "ERROR", e);
response->rmcpStatusCode =
static_cast<uint8_t>(RAKP_ReturnCode::INVALID_SESSION_ID);
return outPayload;
@@ -162,7 +159,7 @@
if (inPayload.size() != (sizeof(RAKP3request) + output.size()) ||
std::memcmp(output.data(), request + 1, output.size()))
{
- log<level::INFO>("Mismatch in HMAC sent by remote console");
+ lg2::info("Mismatch in HMAC sent by remote console");
response->messageTag = request->messageTag;
response->rmcpStatusCode =
diff --git a/command/session_cmds.cpp b/command/session_cmds.cpp
index 8a4014a..1405b6b 100644
--- a/command/session_cmds.cpp
+++ b/command/session_cmds.cpp
@@ -7,7 +7,7 @@
#include <ipmid/sessionhelper.hpp>
#include <ipmid/utils.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <chrono>
@@ -15,7 +15,6 @@
namespace command
{
-using namespace phosphor::logging;
std::vector<uint8_t>
setSessionPrivilegeLevel(const std::vector<uint8_t>& inPayload,
@@ -119,10 +118,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Failed in getting session state property",
- entry("service=%s", service.c_str()),
- entry("object path=%s", obj.c_str()),
- entry("interface=%s", session::sessionIntf));
+ lg2::error(
+ "Failed in getting session state property: {SERVICE}, {PATH}, {INTERFACE}",
+ "SERVICE", service, "PATH", obj, "INTERFACE", session::sessionIntf);
return ipmi::ccUnspecifiedError;
}
@@ -170,9 +168,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Failed to fetch object from dbus",
- entry("INTERFACE=%s", session::sessionIntf),
- entry("ERRMSG=%s", e.what()));
+ lg2::error(
+ "Failed to fetch object from dbus, interface: {INTERFACE}, error: {ERROR}",
+ "INTERFACE", session::sessionIntf, "ERROR", e);
return ipmi::ccUnspecifiedError;
}
@@ -199,9 +197,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Failed to get session manager instance or sessionID "
- "by sessionHandle",
- entry("ERRMSG=%s", e.what()));
+ lg2::error(
+ "Failed to get session manager instance or sessionID by sessionHandle: {ERROR}",
+ "ERROR", e);
return session::ccInvalidSessionHandle;
}
@@ -218,8 +216,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Failed to get session manager instance or sessionID",
- entry("ERRMSG=%s", e.what()));
+ lg2::error(
+ "Failed to get session manager instance or sessionID: {ERROR}",
+ "ERROR", e);
return session::ccInvalidSessionId;
}
@@ -234,9 +233,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(
- "Failed to get session manager instance or stop session",
- entry("ERRMSG=%s", e.what()));
+ lg2::error(
+ "Failed to get session manager instance or stop session: {ERROR}",
+ "ERROR", e);
return ipmi::ccUnspecifiedError;
}
@@ -300,9 +299,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Failed to fetch object from dbus",
- entry("INTERFACE=%s", session::sessionIntf),
- entry("ERRMSG=%s", e.what()));
+ lg2::error(
+ "Failed to fetch object from dbus, interface: {INTERFACE}, error: {ERROR}",
+ "INTERFACE", session::sessionIntf, "ERROR", e);
response->completionCode = ipmi::ccUnspecifiedError;
return outPayload;
}
diff --git a/command/sol_cmds.cpp b/command/sol_cmds.cpp
index 8203a6e..ceee3d8 100644
--- a/command/sol_cmds.cpp
+++ b/command/sol_cmds.cpp
@@ -4,7 +4,7 @@
#include "sol/sol_context.hpp"
#include "sol/sol_manager.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace sol
{
@@ -43,7 +43,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(e.what());
+ lg2::error("Failed to call the getContext method: {ERROR}", "ERROR", e);
return std::vector<uint8_t>();
}
diff --git a/command_table.cpp b/command_table.cpp
index 00acc65..c0e655a 100644
--- a/command_table.cpp
+++ b/command_table.cpp
@@ -7,16 +7,11 @@
#include <ipmid/types.hpp>
#include <main.hpp>
-#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <user_channel/user_layer.hpp>
-#include <xyz/openbmc_project/Common/error.hpp>
#include <iomanip>
-using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-using namespace phosphor::logging;
-
namespace command
{
@@ -26,9 +21,8 @@
if (command)
{
- log<level::DEBUG>(
- "Already Registered",
- phosphor::logging::entry("SKIPPED_ENTRY=0x%x", inCommand.command));
+ lg2::debug("Already Registered: {COMMAND}", "COMMAND",
+ inCommand.command);
return;
}
@@ -50,10 +44,10 @@
// Do not forward any session zero commands to ipmid
if (handler->sessionID == session::sessionZero)
{
- log<level::INFO>("Table: refuse to forward session-zero command",
- entry("LUN=%x", command.lun()),
- entry("NETFN=%x", command.netFn()),
- entry("CMD=%x", command.cmd()));
+ lg2::info(
+ "Table: refuse to forward session-zero command: lun: {LUN}, netFn: {NETFN}, command: {COMMAND}",
+ "LUN", command.lun(), "NETFN", command.netFn(), "COMMAND",
+ command.cmd());
return;
}
std::shared_ptr<session::Session> session =
@@ -137,8 +131,8 @@
// exceeded message
if (elapsedSeconds > 2s)
{
- log<level::ERR>("IPMI command timed out",
- entry("DELAY=%zu", elapsedSeconds.count()));
+ lg2::error("IPMI command timed out: {DELAY}", "DELAY",
+ elapsedSeconds.count());
}
}
}
@@ -154,10 +148,10 @@
{
errResponse.resize(1);
errResponse[0] = IPMI_CC_INSUFFICIENT_PRIVILEGE;
- log<level::INFO>("Table: Insufficient privilege for command",
- entry("LUN=%x", command.lun()),
- entry("NETFN=%x", command.netFn()),
- entry("CMD=%x", command.cmd()));
+ lg2::info(
+ "Table: Insufficient privilege for command: lun: {LUN}, netFn: {NETFN}, command: {COMMAND}",
+ "LUN", command.lun(), "NETFN", command.netFn(), "COMMAND",
+ command.cmd());
return errResponse;
}
diff --git a/main.cpp b/main.cpp
index fc9a28c..b66c6f5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -19,14 +19,12 @@
#include <unistd.h>
#include <CLI/CLI.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <user_channel/channel_layer.hpp>
#include <tuple>
-using namespace phosphor::logging;
-
static auto io = std::make_shared<boost::asio::io_context>();
std::shared_ptr<boost::asio::io_context> getIo()
{
@@ -63,9 +61,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Requested channel name is not a valid channel name",
- entry("ERROR=%s", e.what()),
- entry("CHANNEL=%s", channel.c_str()));
+ lg2::error("Requested {NAME} is not a valid channel name: {ERROR}",
+ "NAME", channel, "ERROR", e);
}
}
EInterfaceIndex getInterfaceIndex(void)
@@ -88,8 +85,8 @@
auto rc = sd_bus_default_system(&bus);
if (rc < 0)
{
- log<level::ERR>("Failed to connect to system bus",
- entry("ERROR=%s", strerror(-rc)));
+ lg2::error("Failed to connect to system bus: {ERROR}", "ERROR",
+ strerror(-rc));
return rc;
}
sdbusp = std::make_shared<sdbusplus::asio::connection>(*io, bus);
diff --git a/message_handler.cpp b/message_handler.cpp
index f845228..b7314b8 100644
--- a/message_handler.cpp
+++ b/message_handler.cpp
@@ -8,17 +8,14 @@
#include <sys/socket.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <memory>
#include <string>
#include <vector>
-using namespace phosphor::logging;
-
namespace message
{
-using namespace phosphor::logging;
bool Handler::receive()
{
@@ -31,7 +28,7 @@
// Read of the packet failed
if (readStatus < 0)
{
- log<level::ERR>("Error in Read", entry("STATUS=%x", readStatus));
+ lg2::error("Error in Read status: {STATUS}", "STATUS", readStatus);
return false;
}
@@ -82,8 +79,7 @@
catch (const std::exception& e)
{
// send failed, most likely due to a session closure
- log<level::INFO>("Async RMCP+ reply failed",
- entry("EXCEPTION=%s", e.what()));
+ lg2::info("Async RMCP+ reply failed: {ERROR}", "ERROR", e);
}
}
diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp
index ca0def9..c4fb762 100644
--- a/sd_event_loop.cpp
+++ b/sd_event_loop.cpp
@@ -3,6 +3,7 @@
#include "main.hpp"
#include "message_handler.hpp"
+#include <error.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
@@ -10,13 +11,12 @@
#include <boost/asio/io_context.hpp>
#include <boost/asio/signal_set.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/sd_event.hpp>
#include <user_channel/channel_layer.hpp>
namespace eventloop
{
-using namespace phosphor::logging;
void EventLoop::handleRmcpPacket()
{
@@ -31,8 +31,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Executing the IPMI message failed",
- entry("EXCEPTION=%s", e.what()));
+ lg2::error("Executing the IPMI message failed: {ERROR}", "ERROR", e);
}
}
@@ -70,7 +69,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("getVLANID: failed to execute/read GetSubTree");
+ lg2::error("getVLANID: failed to execute/read GetSubTree: {ERROR}",
+ "ERROR", e);
return 0;
}
@@ -124,15 +124,15 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("getVLANID: failed to execute/read VLAN Id");
+ lg2::error("getVLANID: failed to execute/read VLAN Id: {ERROR}",
+ "ERROR", e);
return 0;
}
vlanid = std::get<uint32_t>(value);
if ((vlanid & VLAN_VALUE_MASK) != vlanid)
{
- log<level::ERR>("networkd returned an invalid vlan",
- entry("VLAN=%", vlanid));
+ lg2::error("networkd returned an invalid vlan: {VLAN}", "VLAN", vlanid);
return 0;
}
@@ -156,15 +156,15 @@
if (vlanid)
{
iface = iface + "." + std::to_string(vlanid);
- log<level::DEBUG>("This channel has VLAN id",
- entry("VLANID=%d", vlanid));
+ lg2::debug("This channel has VLAN id: {VLAN}", "VLAN", vlanid);
}
}
// Create our own socket if SysD did not supply one.
int listensFdCount = sd_listen_fds(0);
if (listensFdCount > 1)
{
- log<level::ERR>("Too many file descriptors received");
+ lg2::error("Too many file descriptors received, listensFdCount: {FD}",
+ "FD", listensFdCount);
return EXIT_FAILURE;
}
if (listensFdCount == 1)
@@ -172,7 +172,8 @@
int openFd = SD_LISTEN_FDS_START;
if (!sd_is_socket(openFd, AF_UNSPEC, SOCK_DGRAM, -1))
{
- log<level::ERR>("Failed to set up systemd-passed socket");
+ lg2::error("Failed to set up systemd-passed socket: {ERROR}",
+ "ERROR", strerror(errno));
return EXIT_FAILURE;
}
udpSocket = std::make_shared<boost::asio::ip::udp::socket>(
@@ -196,8 +197,8 @@
if ((::getsockopt(udpSocket->native_handle(), SOL_SOCKET, SO_BINDTODEVICE,
nameout, &lenout) == -1))
{
- log<level::ERR>("Failed to read bound device",
- entry("ERROR=%s", strerror(errno)));
+ lg2::error("Failed to read bound device: {ERROR}", "ERROR",
+ strerror(errno));
}
if (iface != nameout && iface != unboundIface)
{
@@ -206,12 +207,11 @@
SO_BINDTODEVICE, iface.c_str(),
iface.size() + 1) == -1))
{
- log<level::ERR>("Failed to bind to requested interface",
- entry("ERROR=%s", strerror(errno)));
+ lg2::error("Failed to bind to requested interface: {ERROR}",
+ "ERROR", strerror(errno));
return EXIT_FAILURE;
}
- log<level::INFO>("Bind to interface",
- entry("INTERFACE=%s", iface.c_str()));
+ lg2::info("Bind to interface: {INTERFACE}", "INTERFACE", iface);
}
// cannot be constexpr because it gets passed by address
const int option_enabled = 1;
@@ -229,9 +229,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Failed to acquire D-Bus name",
- entry("NAME=%s", busName.c_str()),
- entry("ERROR=%s", e.what()));
+ lg2::error("Failed to acquire D-Bus name: {NAME}: {ERROR}", "NAME",
+ busName, "ERROR", e);
return EXIT_FAILURE;
}
return 0;
diff --git a/sessions_manager.cpp b/sessions_manager.cpp
index 538aaa4..5c9789b 100644
--- a/sessions_manager.cpp
+++ b/sessions_manager.cpp
@@ -3,7 +3,7 @@
#include "main.hpp"
#include "session.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <user_channel/channel_layer.hpp>
@@ -12,8 +12,6 @@
#include <iomanip>
#include <memory>
-using namespace phosphor::logging;
-
namespace session
{
@@ -171,7 +169,7 @@
return session;
}
- log<level::INFO>("No free RMCP+ sessions left");
+ lg2::info("No free RMCP+ sessions left");
throw std::runtime_error("No free sessions left");
}
@@ -265,11 +263,10 @@
}
if (!(session->isSessionActive(activeGrace, setupGrace)))
{
- log<level::INFO>(
- "Removing idle IPMI LAN session",
- entry("SESSION_ID=%x", session->getBMCSessionID()),
- entry("HANDLE=%x",
- getSessionHandle(session->getBMCSessionID())));
+ lg2::info(
+ "Removing idle IPMI LAN session, id: {ID}, handler: {HANDLE}",
+ "ID", session->getBMCSessionID(), "HANDLE",
+ getSessionHandle(session->getBMCSessionID()));
sessionHandleMap[getSessionHandle(session->getBMCSessionID())] = 0;
iter = sessionsMap.erase(iter);
}
diff --git a/socket_channel.hpp b/socket_channel.hpp
index 7179e2c..0edfcd5 100644
--- a/socket_channel.hpp
+++ b/socket_channel.hpp
@@ -4,7 +4,7 @@
#include <sys/types.h>
#include <boost/asio/ip/udp.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <memory>
#include <optional>
@@ -99,9 +99,7 @@
{
return retval;
}
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error in inet_ntop",
- phosphor::logging::entry("ERROR=%s", strerror(errno)));
+ lg2::error("Error in inet_ntop: {ERROR}", "ERROR", strerror(errno));
return std::string();
}
@@ -154,9 +152,8 @@
if (bytesReceived < 0)
{
// something bad happened; bail
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error in recvmsg",
- phosphor::logging::entry("ERROR=%s", strerror(errno)));
+ lg2::error("Error in recvmsg: {ERROR}", "ERROR",
+ strerror(-bytesReceived));
return std::make_tuple(-errno, std::vector<uint8_t>());
}
// save the size of either ipv4 or i4v6 sockaddr
@@ -224,9 +221,7 @@
int ret = sendmsg(socket->native_handle(), &msg, 0);
if (ret < 0)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error in sendmsg",
- phosphor::logging::entry("ERROR=%s", strerror(errno)));
+ lg2::error("Error in sendmsg: {ERROR}", "ERROR", strerror(-ret));
}
return ret;
}
diff --git a/sol/sol_context.cpp b/sol/sol_context.cpp
index 4428c9c..4702bbe 100644
--- a/sol/sol_context.cpp
+++ b/sol/sol_context.cpp
@@ -6,7 +6,9 @@
#include "sessions_manager.hpp"
#include "sol_manager.hpp"
-#include <phosphor-logging/log.hpp>
+#include <errno.h>
+
+#include <phosphor-logging/lg2.hpp>
namespace sol
{
@@ -96,7 +98,7 @@
*/
if (seqNum && (seqNum != seqNums.get(true)))
{
- log<level::INFO>("Out of sequence SOL packet - packet is dropped");
+ lg2::info("Out of sequence SOL packet - packet is dropped");
return;
}
@@ -108,7 +110,7 @@
*/
if (ackSeqNum && (ackSeqNum != seqNums.get(false)))
{
- log<level::INFO>("Out of sequence ack number - SOL packet is dropped");
+ lg2::info("Out of sequence ack number - SOL packet is dropped");
return;
}
@@ -149,7 +151,8 @@
auto rc = sol::Manager::get().writeConsoleSocket(input);
if (rc)
{
- log<level::ERR>("Writing to console socket descriptor failed");
+ lg2::error("Writing to console socket descriptor failed: {ERROR}",
+ "ERROR", strerror(errno));
ack = true;
}
else
@@ -283,7 +286,8 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(e.what());
+ lg2::error("Failed to call the sendOutboundPayload method: {ERROR}",
+ "ERROR", e);
}
}
@@ -307,7 +311,7 @@
}
catch (const std::exception& e)
{
- log<level::ERR>(e.what());
+ lg2::error("Failed to retry timer: {ERROR}", "ERROR", e);
}
}
} // namespace sol
diff --git a/sol/sol_manager.cpp b/sol/sol_manager.cpp
index 3c01212..42296e3 100644
--- a/sol/sol_manager.cpp
+++ b/sol/sol_manager.cpp
@@ -11,7 +11,7 @@
#include <boost/asio/local/stream_protocol.hpp>
#include <boost/asio/write.hpp>
#include <ipmid/utils.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/message/types.hpp>
#include <chrono>
@@ -24,8 +24,6 @@
namespace sol
{
-using namespace phosphor::logging;
-
std::unique_ptr<sdbusplus::bus::match_t> matchPtrSOL(nullptr);
std::unique_ptr<sdbusplus::bus::match_t> solConfPropertiesSignal(nullptr);
@@ -51,8 +49,9 @@
}
else
{
- log<level::ERR>("Reading ready count from host console socket failed:",
- entry("EXCEPTION=%s", ec.message().c_str()));
+ lg2::error(
+ "Reading ready count from host console socket failed: {ERROR}",
+ "ERROR", ec.value());
return;
}
std::vector<uint8_t> buffer(readSize);
@@ -61,8 +60,8 @@
consoleSocket->read_some(boost::asio::buffer(buffer), ec);
if (ec)
{
- log<level::ERR>("Reading from host console socket failed:",
- entry("EXCEPTION=%s", ec.message().c_str()));
+ lg2::error("Reading from host console socket failed: {ERROR}", "ERROR",
+ ec.value());
return;
}
@@ -128,8 +127,7 @@
catch (const std::runtime_error& e)
{
solService.clear();
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error: get SOL service failed");
+ lg2::error("Get SOL service failed: {ERROR}", "ERROR", e);
return;
}
}
@@ -138,10 +136,9 @@
properties = ipmi::getAllDbusProperties(
dbus, solService, solPathWitheEthName, solInterface);
}
- catch (const std::runtime_error&)
+ catch (const std::runtime_error& e)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "Error setting sol parameter");
+ lg2::error("Setting sol parameter: {ERROR}", "ERROR", e);
return;
}
@@ -181,9 +178,9 @@
}
catch (const std::exception& e)
{
- log<level::ERR>("Encountered exception when starting host console. "
- "Hence stopping host console.",
- entry("EXCEPTION=%s", e.what()));
+ lg2::error(
+ "Encountered exception when starting host console. Hence stopping host console: {ERROR}",
+ "ERROR", e);
stopHostConsole();
throw;
}
@@ -265,8 +262,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>(
- "Failed to get service path in registerSOLServiceChangeCallback");
+ lg2::error(
+ "Failed to get service path in registerSOLServiceChangeCallback: {ERROR}",
+ "ERROR", e);
}
}
@@ -285,9 +283,8 @@
}
catch (const std::exception& e)
{
- phosphor::logging::log<phosphor::logging::level::ERR>(
- "procSolConfChange get properties FAIL",
- entry("ERROR=%s", e.what()));
+ lg2::error("procSolConfChange get properties FAIL: {ERROR}", "ERROR",
+ e);
return;
}
@@ -351,9 +348,9 @@
}
catch (const sdbusplus::exception_t& e)
{
- log<level::ERR>("Failed to get service path in "
- "registerSolConfChangeCallbackHandler",
- entry("CHANNEL=%s", channel.c_str()));
+ lg2::error(
+ "Failed to get service path in registerSolConfChangeCallbackHandler, channel: {CHANNEL}, error: {ERROR}",
+ "CHANNEL", channel, "ERROR", e);
}
}
return;