lg2: convert state-manager
This converts the rest of phosphor-state-manager over to the lg2
interface.
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
Change-Id: I3878ec950b6a2b1ada93544cc021cecf14edfb46
diff --git a/bmc_state_manager.cpp b/bmc_state_manager.cpp
index 1ce37b3..c3c1c7d 100644
--- a/bmc_state_manager.cpp
+++ b/bmc_state_manager.cpp
@@ -230,9 +230,8 @@
BMC::RebootCause BMC::lastRebootCause(RebootCause value)
{
- log<level::INFO>(
- "Setting the RebootCause field",
- entry("LAST_REBOOT_CAUSE=0x%s", convertForMessage(value).c_str()));
+ info("Setting the RebootCause field to {LAST_REBOOT_CAUSE}",
+ "LAST_REBOOT_CAUSE", value);
return server::BMC::lastRebootCause(value);
}
@@ -269,10 +268,8 @@
catch (const std::exception& e)
{
auto rc = errno;
- log<level::ERR>((std::string("Failed to read sysfs file "
- "errno=") +
- std::to_string(rc) + " FILENAME=" + bootstatusPath)
- .c_str());
+ error("Failed to read sysfs file {FILE} with errno {ERRNO}", "FILE",
+ bootstatusPath, "ERRNO", rc);
}
switch (bootReason)
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp
index 2dd57eb..f4e761a 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -5,11 +5,9 @@
#include "xyz/openbmc_project/Common/error.hpp"
#include "xyz/openbmc_project/State/Shutdown/Power/error.hpp"
-#include <fmt/format.h>
-
#include <cereal/archives/json.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/exception.hpp>
#include <sdeventplus/event.hpp>
@@ -25,6 +23,8 @@
namespace manager
{
+PHOSPHOR_LOG2_USING;
+
// When you see server:: you know we're referencing our base class
namespace server = sdbusplus::xyz::openbmc_project::State::server;
@@ -61,10 +61,9 @@
SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, SYSTEMD_INTERFACE, "Subscribe");
this->bus.call(method);
}
- catch (const sdbusplus::exception::exception& ex)
+ catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Failed to subscribe to systemd signals",
- entry("ERR=%s", ex.what()));
+ error("Failed to subscribe to systemd signals: {ERROR}", "ERROR", e);
elog<InternalFailure>();
}
@@ -89,9 +88,7 @@
if (std::get<int>(pgood) == 1)
{
- log<level::INFO>("Initial Chassis State will be On",
- entry("CHASSIS_CURRENT_POWER_STATE=%s",
- convertForMessage(PowerState::On).c_str()));
+ info("Initial Chassis State will be On");
server::Chassis::currentPowerState(PowerState::On);
server::Chassis::requestedPowerTransition(Transition::On);
return;
@@ -125,15 +122,12 @@
}
// Only log for unexpected error types.
- log<level::ERR>("Error performing call to get pgood",
- entry("ERROR=%s", e.what()));
+ error("Error performing call to get pgood: {ERROR}", "ERROR", e);
goto fail;
}
fail:
- log<level::INFO>("Initial Chassis State will be Off",
- entry("CHASSIS_CURRENT_POWER_STATE=%s",
- convertForMessage(PowerState::Off).c_str()));
+ info("Initial Chassis State will be Off");
server::Chassis::currentPowerState(PowerState::Off);
server::Chassis::requestedPowerTransition(Transition::Off);
@@ -172,7 +166,7 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in GetUnit call", entry("ERROR=%s", e.what()));
+ error("Error in GetUnit call: {ERROR}", "ERROR", e);
return false;
}
@@ -190,8 +184,7 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in ActiveState Get",
- entry("ERROR=%s", e.what()));
+ error("Error in ActiveState Get: {ERROR}", "ERROR", e);
return false;
}
@@ -216,16 +209,15 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in state change - bad encoding",
- entry("ERROR=%s", e.what()),
- entry("REPLY_SIG=%s", msg.get_signature()));
+ error("Error in state change - bad encoding: {ERROR} {REPLY_SIG}",
+ "ERROR", e, "REPLY_SIG", msg.get_signature());
return 0;
}
if ((newStateUnit == CHASSIS_STATE_POWEROFF_TGT) &&
(newStateResult == "done") && (!stateActive(CHASSIS_STATE_POWERON_TGT)))
{
- log<level::INFO>("Received signal that power OFF is complete");
+ info("Received signal that power OFF is complete");
this->currentPowerState(server::Chassis::PowerState::Off);
this->setStateChangeTime();
}
@@ -233,7 +225,7 @@
(newStateResult == "done") &&
(stateActive(CHASSIS_STATE_POWERON_TGT)))
{
- log<level::INFO>("Received signal that power ON is complete");
+ info("Received signal that power ON is complete");
this->currentPowerState(server::Chassis::PowerState::On);
this->setStateChangeTime();
@@ -258,9 +250,8 @@
Chassis::Transition Chassis::requestedPowerTransition(Transition value)
{
- log<level::INFO>(fmt::format("Change to Chassis Requested Power State: {}",
- convertForMessage(value))
- .c_str());
+ info("Change to Chassis Requested Power State: {REQ_POWER_TRAN}",
+ "REQ_POWER_TRAN", value);
executeTransition(value);
return server::Chassis::requestedPowerTransition(value);
}
@@ -268,9 +259,8 @@
Chassis::PowerState Chassis::currentPowerState(PowerState value)
{
PowerState chassisPowerState;
- log<level::INFO>(fmt::format("Change to Chassis Power State: {}",
- convertForMessage(value))
- .c_str());
+ info("Change to Chassis Power State: {CUR_POWER_STATE}", "CUR_POWER_STATE",
+ value);
chassisPowerState = server::Chassis::currentPowerState(value);
pohTimer.setEnabled(chassisPowerState == PowerState::On);
@@ -332,7 +322,7 @@
}
catch (cereal::Exception& e)
{
- log<level::ERR>(e.what());
+ error("deserialize exception: {ERROR}", "ERROR", e);
fs::remove(path);
return false;
}
@@ -357,8 +347,8 @@
}
catch (const sdeventplus::SdEventError& e)
{
- log<level::ERR>("Error occurred during the sdeventplus loop",
- entry("ERROR=%s", e.what()));
+ error("Error occurred during the sdeventplus loop: {ERROR}", "ERROR",
+ e);
phosphor::logging::commit<InternalFailure>();
}
}
@@ -389,7 +379,7 @@
}
catch (std::exception& e)
{
- log<level::ERR>(e.what());
+ error("deserialize exception: {ERROR}", "ERROR", e);
fs::remove(path);
}
diff --git a/discover_system_state.cpp b/discover_system_state.cpp
index d440c00..446959d 100644
--- a/discover_system_state.cpp
+++ b/discover_system_state.cpp
@@ -9,7 +9,7 @@
#include <systemd/sd-bus.h>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <sdbusplus/server.hpp>
@@ -24,6 +24,8 @@
namespace manager
{
+PHOSPHOR_LOG2_USING;
+
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
using namespace sdbusplus::xyz::openbmc_project::Control::Power::server;
@@ -50,17 +52,17 @@
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
- log<level::ERR>("Error reading mapper response",
- entry("PATH=%s", path.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ error("Mapper response empty, does not have path {PATH} and "
+ "interface {INTERFACE}",
+ "PATH", path, "INTERFACE", interface);
throw std::runtime_error("Error reading mapper response");
}
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in mapper call", entry("ERROR=%s", e.what()),
- entry("PATH=%s", path.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ error("Error in mapper call for path {PATH} and interface {INTERFACE} "
+ "with error {ERROR}",
+ "PATH", path, "INTERFACE", interface, "ERROR", e);
throw;
}
@@ -85,15 +87,15 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in property Get", entry("ERROR=%s", e.what()),
- entry("PROPERTY=%s", propertyName.c_str()));
+ error("Error in property Get, error {ERROR}, property {PROPERTY}",
+ "ERROR", e, "PROPERTY", propertyName);
throw;
}
if (std::get<std::string>(property).empty())
{
- log<level::ERR>("Error reading property response",
- entry("PROPERTY=%s", propertyName.c_str()));
+ error("Error reading property response for {PROPERTY}", "PROPERTY",
+ propertyName);
throw std::runtime_error("Error reading property response");
}
@@ -182,8 +184,7 @@
RestorePolicy::convertPolicyFromString(powerPolicy))
{
// one_time is set to None so use the customer setting
- log<level::INFO>(
- "One time not set, check user setting of power policy");
+ info("One time not set, check user setting of power policy");
auto reply = bus.call(methodUserSetting);
reply.read(result);
powerPolicy = std::get<std::string>(result);
@@ -192,26 +193,26 @@
{
// one_time setting was set so we're going to use it. Reset it
// to default for next time.
- log<level::INFO>("One time set, use it and reset to default");
+ info("One time set, use it and reset to default");
setProperty(bus, settings.powerRestorePolicyOneTime.c_str(),
powerRestoreIntf, "PowerRestorePolicy",
convertForMessage(RestorePolicy::Policy::None));
}
- log<level::INFO>("Host power is off, processing power policy",
- entry("POWER_POLICY=%s", powerPolicy.c_str()));
+ info("Host power is off, processing power policy {POWER_POLICY}",
+ "POWER_POLICY", powerPolicy);
if (RestorePolicy::Policy::AlwaysOn ==
RestorePolicy::convertPolicyFromString(powerPolicy))
{
- log<level::INFO>("power_policy=ALWAYS_POWER_ON, powering host on");
+ info("power_policy=ALWAYS_POWER_ON, powering host on");
setProperty(bus, hostPath, HOST_BUSNAME, "RequestedHostTransition",
convertForMessage(server::Host::Transition::On));
}
else if (RestorePolicy::Policy::Restore ==
RestorePolicy::convertPolicyFromString(powerPolicy))
{
- log<level::INFO>("power_policy=RESTORE, restoring last state");
+ info("power_policy=RESTORE, restoring last state");
// Read last requested state and re-request it to execute it
auto hostReqState = getProperty(bus, hostPath, HOST_BUSNAME,
@@ -222,8 +223,7 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in PowerRestorePolicy Get",
- entry("ERROR=%s", e.what()));
+ error("Error in PowerRestorePolicy Get: {ERROR}", "ERROR", e);
elog<InternalFailure>();
}
diff --git a/host_check.cpp b/host_check.cpp
index 81dff7f..389c5e6 100644
--- a/host_check.cpp
+++ b/host_check.cpp
@@ -5,7 +5,7 @@
#include <unistd.h>
#include <boost/range/adaptor/reversed.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/exception.hpp>
#include <xyz/openbmc_project/Condition/HostFirmware/server.hpp>
@@ -17,8 +17,16 @@
#include <thread>
#include <vector>
+namespace phosphor
+{
+namespace state
+{
+namespace manager
+{
+
+PHOSPHOR_LOG2_USING;
+
using namespace std::literals;
-using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Condition::server;
// Required strings for sending the msg to check on host
@@ -55,16 +63,15 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>(
- "Error in mapper GetSubTree call for HostFirmware condition",
- entry("ERROR=%s", e.what()));
+ error("Error in mapper GetSubTree call for HostFirmware condition: "
+ "{ERROR}",
+ "ERROR", e);
throw;
}
if (mapperResponse.empty())
{
- log<level::INFO>(
- "Mapper response for HostFirmware conditions is empty!");
+ info("Mapper response for HostFirmware conditions is empty!");
return false;
}
@@ -106,10 +113,9 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error reading HostFirmware condition",
- entry("ERROR=%s", e.what()),
- entry("SERVICE=%s", service.c_str()),
- entry("PATH=%s", path.c_str()));
+ error("Error reading HostFirmware condition, error: {ERROR}, "
+ "service: {SERVICE} path: {PATH}",
+ "ERROR", e, "SERVICE", service, "PATH", path);
throw;
}
}
@@ -139,11 +145,10 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error reading Chassis Power State",
- entry("ERROR=%s", e.what()),
- entry("SERVICE=%s", CHASSIS_STATE_SVC),
- entry("PATH=%s", CHASSIS_STATE_PATH));
-
+ error("Error reading Chassis Power State, error: {ERROR}, "
+ "service: {SERVICE} path: {PATH}",
+ "ERROR", e, "SERVICE", CHASSIS_STATE_SVC, "PATH",
+ CHASSIS_STATE_PATH);
throw;
}
return false;
@@ -151,14 +156,14 @@
bool isHostRunning()
{
- log<level::INFO>("Check if host is running");
+ info("Check if host is running");
auto bus = sdbusplus::bus::new_default();
// No need to check if chassis power is not on
if (!isChassiPowerOn(bus))
{
- log<level::INFO>("Chassis power not on, exit");
+ info("Chassis power not on, exit");
return false;
}
@@ -178,7 +183,7 @@
std::this_thread::sleep_for(std::chrono::milliseconds(500));
if (checkFirmwareConditionRunning(bus))
{
- log<level::INFO>("Host is running!");
+ info("Host is running!");
// Create file for host instance and create in filesystem to
// indicate to services that host is running
auto size = std::snprintf(nullptr, 0, HOST_RUNNING_FILE, 0);
@@ -190,6 +195,10 @@
return true;
}
}
- log<level::INFO>("Host is not running!");
+ info("Host is not running!");
return false;
}
+
+} // namespace manager
+} // namespace state
+} // namespace phosphor
diff --git a/host_check.hpp b/host_check.hpp
index 0634f61..1a64912 100644
--- a/host_check.hpp
+++ b/host_check.hpp
@@ -1,7 +1,18 @@
#pragma once
+namespace phosphor
+{
+namespace state
+{
+namespace manager
+{
+
/** @brief Determine if host is running
*
* @return True if host running, False otherwise
*/
bool isHostRunning();
+
+} // namespace manager
+} // namespace state
+} // namespace phosphor
diff --git a/host_reset_recovery.cpp b/host_reset_recovery.cpp
index f138c3c..4ba1c60 100644
--- a/host_reset_recovery.cpp
+++ b/host_reset_recovery.cpp
@@ -3,7 +3,7 @@
#include <unistd.h>
#include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/exception.hpp>
#include <xyz/openbmc_project/Logging/Create/server.hpp>
@@ -13,6 +13,15 @@
#include <fstream>
#include <string>
+namespace phosphor
+{
+namespace state
+{
+namespace manager
+{
+
+PHOSPHOR_LOG2_USING;
+
constexpr auto HOST_STATE_SVC = "xyz.openbmc_project.State.Host";
constexpr auto HOST_STATE_PATH = "/xyz/openbmc_project/state/host0";
constexpr auto PROPERTY_INTERFACE = "org.freedesktop.DBus.Properties";
@@ -28,8 +37,6 @@
constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
constexpr auto HOST_STATE_QUIESCE_TGT = "obmc-host-quiesce@0.target";
-using namespace phosphor::logging;
-
bool wasHostBooting(sdbusplus::bus::bus& bus)
{
try
@@ -47,20 +54,18 @@
"xyz.openbmc_project.State.Boot.Progress.ProgressStages."
"Unspecified")
{
- log<level::INFO>("Host was not booting before BMC reboot");
+ info("Host was not booting before BMC reboot");
return false;
}
- log<level::INFO>("Host was booting before BMC reboot",
- entry("BOOTPROGRESS=%s",
- std::get<std::string>(bootProgress).c_str()));
+ info("Host was booting before BMC reboot: {BOOTPROGRESS}",
+ "BOOTPROGRESS", std::get<std::string>(bootProgress));
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error reading BootProgress",
- entry("ERROR=%s", e.what()),
- entry("SERVICE=%s", HOST_STATE_SVC),
- entry("PATH=%s", HOST_STATE_PATH));
+ error("Error reading BootProgress, error {ERROR}, service {SERVICE}, "
+ "path {PATH}",
+ "ERROR", e, "SERVICE", HOST_STATE_SVC, "PATH", HOST_STATE_PATH);
throw;
}
@@ -89,18 +94,18 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("sdbusplus D-Bus call exception",
- entry("OBJPATH=%s", LOGGING_PATH),
- entry("INTERFACE=%s", LOGGING_CREATE_INTF),
- entry("EXCEPTION=%s", e.what()));
+ error(
+ "sdbusplus D-Bus call exception, error {ERROR}, objpath {OBJPATH}, "
+ "interface {INTERFACE}",
+ "ERROR", e, "OBJPATH", LOGGING_PATH, "INTERFACE",
+ LOGGING_CREATE_INTF);
throw std::runtime_error(
"Error in invoking D-Bus logging create interface");
}
catch (std::exception& e)
{
- log<level::ERR>("D-bus call exception",
- entry("EXCEPTION=%s", e.what()));
+ error("D-bus call exception: {ERROR}", "ERROR", e);
throw e;
}
}
@@ -132,16 +137,22 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("sdbusplus call exception starting quiesce target",
- entry("EXCEPTION=%s", e.what()));
+ error("sdbusplus call exception starting quiesce target: {ERROR}",
+ "ERROR", e);
throw std::runtime_error(
"Error in invoking D-Bus systemd StartUnit method");
}
}
+} // namespace manager
+} // namespace state
+} // namespace phosphor
+
int main()
{
+ using namespace phosphor::state::manager;
+ PHOSPHOR_LOG2_USING;
auto bus = sdbusplus::bus::new_default();
@@ -150,15 +161,15 @@
// another systemd target transition (i.e. Quiesce->Reboot)
while (!isChassisTargetComplete())
{
- log<level::DEBUG>("Waiting for chassis on target to complete");
+ debug("Waiting for chassis on target to complete");
std::this_thread::sleep_for(std::chrono::seconds(1));
// There is no timeout here, wait until it happens or until system
// is powered off and this service is stopped
}
- log<level::INFO>("Chassis power on has completed, checking if host is "
- "still running after the BMC reboot");
+ info("Chassis power on has completed, checking if host is "
+ "still running after the BMC reboot");
// Check the last BootProgeress to see if the host was booting before
// the BMC reboot occurred
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 00f41cb..4611e34 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -4,7 +4,6 @@
#include "host_check.hpp"
-#include <fmt/format.h>
#include <stdio.h>
#include <systemd/sd-bus.h>
@@ -14,7 +13,7 @@
#include <cereal/types/tuple.hpp>
#include <cereal/types/vector.hpp>
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -36,6 +35,8 @@
namespace manager
{
+PHOSPHOR_LOG2_USING;
+
// When you see server:: or reboot:: you know we're referencing our base class
namespace server = sdbusplus::xyz::openbmc_project::State::server;
namespace reboot = sdbusplus::xyz::openbmc_project::Control::Boot::server;
@@ -97,8 +98,7 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Failed to subscribe to systemd signals",
- entry("ERR=%s", e.what()));
+ error("Failed to subscribe to systemd signals: {ERROR}", "ERROR", e);
elog<InternalFailure>();
}
return;
@@ -109,17 +109,13 @@
if (stateActive(HOST_STATE_POWERON_MIN_TGT) || isHostRunning())
{
- log<level::INFO>("Initial Host State will be Running",
- entry("CURRENT_HOST_STATE=%s",
- convertForMessage(HostState::Running).c_str()));
+ info("Initial Host State will be Running");
server::Host::currentHostState(HostState::Running);
server::Host::requestedHostTransition(Transition::On);
}
else
{
- log<level::INFO>("Initial Host State will be Off",
- entry("CURRENT_HOST_STATE=%s",
- convertForMessage(HostState::Off).c_str()));
+ info("Initial Host State will be Off");
server::Host::currentHostState(HostState::Off);
server::Host::requestedHostTransition(Transition::Off);
}
@@ -165,7 +161,7 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in GetUnit call", entry("ERROR=%s", e.what()));
+ error("Error in GetUnit call: {ERROR}", "ERROR", e);
return false;
}
@@ -183,8 +179,7 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in ActiveState Get",
- entry("ERROR=%s", e.what()));
+ error("Error in ActiveState Get: {ERROR}", "ERROR", e);
return false;
}
@@ -221,7 +216,7 @@
if (!autoReboot)
{
- log<level::INFO>("Auto reboot (one-time) disabled");
+ info("Auto reboot (one-time) disabled");
return false;
}
else
@@ -239,33 +234,34 @@
if (rebootCounterParam > 0)
{
// Reduce BOOTCOUNT by 1
- log<level::INFO>("Auto reboot enabled, rebooting");
+ info("Auto reboot enabled and boot count at {BOOTCOUNT}, "
+ "rebooting",
+ "BOOTCOUNT", rebootCounterParam);
return true;
}
else if (rebootCounterParam == 0)
{
// Reset reboot counter and go to quiesce state
- log<level::INFO>("Auto reboot enabled. "
- "HOST BOOTCOUNT already set to 0.");
+ info("Auto reboot enabled but HOST BOOTCOUNT already set to 0");
attemptsLeft(BOOT_COUNT_MAX_ALLOWED);
return false;
}
else
{
- log<level::INFO>("Auto reboot enabled. "
- "HOST BOOTCOUNT has an invalid value.");
+ info("Auto reboot enabled but HOST BOOTCOUNT has an invalid "
+ "value");
return false;
}
}
else
{
- log<level::INFO>("Auto reboot disabled.");
+ info("Auto reboot disabled.");
return false;
}
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in AutoReboot Get", entry("ERROR=%s", e.what()));
+ error("Error in AutoReboot Get, {ERROR}", "ERROR", e);
return false;
}
}
@@ -284,7 +280,7 @@
(newStateResult == "done") &&
(!stateActive(HOST_STATE_POWERON_MIN_TGT)))
{
- log<level::INFO>("Received signal that host is off");
+ info("Received signal that host is off");
this->currentHostState(server::Host::HostState::Off);
this->bootProgress(bootprogress::Progress::ProgressStages::Unspecified);
this->operatingSystemState(osstatus::Status::OSStatus::Inactive);
@@ -293,7 +289,7 @@
(newStateResult == "done") &&
(stateActive(HOST_STATE_POWERON_MIN_TGT)))
{
- log<level::INFO>("Received signal that host is running");
+ info("Received signal that host is running");
this->currentHostState(server::Host::HostState::Running);
// Remove temporary file which is utilized for scenarios where the
@@ -316,12 +312,12 @@
{
if (Host::isAutoReboot())
{
- log<level::INFO>("Beginning reboot...");
+ info("Beginning reboot...");
Host::requestedHostTransition(server::Host::Transition::Reboot);
}
else
{
- log<level::INFO>("Maintaining quiesce");
+ info("Maintaining quiesce");
this->currentHostState(server::Host::HostState::Quiesced);
}
}
@@ -338,7 +334,7 @@
if (newStateUnit == HOST_STATE_DIAGNOSTIC_MODE)
{
- log<level::INFO>("Received signal that host is in diagnostice mode");
+ info("Received signal that host is in diagnostice mode");
this->currentHostState(server::Host::HostState::DiagnosticMode);
}
}
@@ -376,7 +372,7 @@
}
catch (cereal::Exception& e)
{
- log<level::ERR>(e.what());
+ error("deserialize exception: {ERROR}", "ERROR", e);
fs::remove(path);
return false;
}
@@ -384,9 +380,7 @@
Host::Transition Host::requestedHostTransition(Transition value)
{
- log<level::INFO>(fmt::format("Host state transition request of {}",
- convertForMessage(value))
- .c_str());
+ info("Host state transition request of {REQ}", "REQ", value);
// If this is not a power off request then we need to
// decrement the reboot counter. This code should
// never prevent a power on, it should just decrement
@@ -420,9 +414,7 @@
Host::HostState Host::currentHostState(HostState value)
{
- log<level::INFO>(
- fmt::format("Change to Host State: {}", convertForMessage(value))
- .c_str());
+ info("Change to Host State: {STATE}", "STATE", value);
return server::Host::currentHostState(value);
}
diff --git a/host_state_manager.hpp b/host_state_manager.hpp
index af22ade..a27cbf5 100644
--- a/host_state_manager.hpp
+++ b/host_state_manager.hpp
@@ -7,7 +7,7 @@
#include <cereal/access.hpp>
#include <cereal/cereal.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Control/Boot/RebootAttempts/server.hpp>
#include <xyz/openbmc_project/State/Boot/Progress/server.hpp>
@@ -30,7 +30,7 @@
sdbusplus::xyz::openbmc_project::Control::Boot::server::RebootAttempts,
sdbusplus::xyz::openbmc_project::State::OperatingSystem::server::Status>;
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
namespace sdbusRule = sdbusplus::bus::match::rules;
namespace fs = std::experimental::filesystem;
@@ -113,7 +113,7 @@
{
// value is ignored in this implementation
(void)(value);
- log<level::DEBUG>("External request to reset reboot count");
+ debug("External request to reset reboot count");
return (sdbusplus::xyz::openbmc_project::Control::Boot::server::
RebootAttempts::attemptsLeft(BOOT_COUNT_MAX_ALLOWED));
}
diff --git a/hypervisor_state_manager.cpp b/hypervisor_state_manager.cpp
index b3afc0c..d0fd193 100644
--- a/hypervisor_state_manager.cpp
+++ b/hypervisor_state_manager.cpp
@@ -2,10 +2,8 @@
#include "hypervisor_state_manager.hpp"
-#include <fmt/format.h>
-
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <sdbusplus/server.hpp>
@@ -21,20 +19,21 @@
namespace manager
{
+PHOSPHOR_LOG2_USING;
+
// When you see server:: you know we're referencing our base class
namespace server = sdbusplus::xyz::openbmc_project::State::server;
using namespace phosphor::logging;
server::Host::Transition Hypervisor::requestedHostTransition(Transition value)
{
- log<level::INFO>(fmt::format("Hypervisor state transition request of {}",
- convertForMessage(value))
- .c_str());
+ info("Hypervisor state transition request of {TRAN_REQUEST}",
+ "TRAN_REQUEST", value);
// Only support the transition to On
if (value != server::Host::Transition::On)
{
- log<level::ERR>("Hypervisor state only supports a transition to On");
+ error("Hypervisor state only supports a transition to On");
// TODO raise appropriate error exception
return server::Host::Transition::Off;
}
@@ -47,9 +46,7 @@
server::Host::HostState Hypervisor::currentHostState(HostState value)
{
- log<level::INFO>(
- fmt::format("Change to Hypervisor State: {}", convertForMessage(value))
- .c_str());
+ info("Change to Hypervisor State: {HYP_STATE}", "HYP_STATE", value);
return server::Host::currentHostState(value);
}
@@ -60,8 +57,7 @@
void Hypervisor::updateCurrentHostState(std::string& bootProgress)
{
- log<level::DEBUG>(
- fmt::format("New BootProgress: {}", bootProgress).c_str());
+ debug("New BootProgress: {BOOTPROGRESS}", "BOOTPROGRESS", bootProgress);
if (bootProgress == "xyz.openbmc_project.State.Boot.Progress."
"ProgressStages.SystemInitComplete")
diff --git a/scheduled_host_transition.cpp b/scheduled_host_transition.cpp
index f2907c5..dd83f4a 100644
--- a/scheduled_host_transition.cpp
+++ b/scheduled_host_transition.cpp
@@ -8,7 +8,7 @@
#include <cereal/archives/json.hpp>
#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/ScheduledTime/error.hpp>
#include <chrono>
@@ -31,6 +31,8 @@
namespace manager
{
+PHOSPHOR_LOG2_USING;
+
namespace fs = std::filesystem;
using namespace std::chrono;
@@ -52,8 +54,8 @@
if (timer.isEnabled())
{
timer.setEnabled(false);
- log<level::DEBUG>("scheduledTime: The function Scheduled Host "
- "Transition is disabled.");
+ debug("scheduledTime: The function Scheduled Host Transition is "
+ "disabled.");
}
}
else
@@ -61,9 +63,8 @@
auto deltaTime = seconds(value) - getTime();
if (deltaTime < seconds(0))
{
- log<level::ERR>(
- "Scheduled time is earlier than current time. Fail to "
- "schedule host transition.");
+ error("Scheduled time is earlier than current time. Fail to "
+ "schedule host transition.");
elog<InvalidTimeError>(
InvalidTime::REASON("Scheduled time is in the past"));
}
@@ -97,8 +98,8 @@
utils::setProperty(bus, hostPath, HOST_BUSNAME, PROPERTY_TRANSITION,
reqTrans);
- log<level::INFO>("Set requestedTransition",
- entry("REQUESTED_TRANSITION=%s", reqTrans.c_str()));
+ info("Set requestedTransition to {REQUESTED_TRANSITION}",
+ "REQUESTED_TRANSITION", reqTrans);
}
void ScheduledHostTransition::callback()
@@ -126,8 +127,8 @@
if (timeFd == -1)
{
auto eno = errno;
- log<level::ERR>("Failed to create timerfd", entry("ERRNO=%d", eno),
- entry("RC=%d", timeFd));
+ error("Failed to create timerfd, errno: {ERRNO}, rc: {RC}", "ERRNO",
+ eno, "RC", timeFd);
throw std::system_error(eno, std::system_category());
}
@@ -141,8 +142,8 @@
if (r != 0)
{
auto eno = errno;
- log<level::ERR>("Failed to set timerfd", entry("ERRNO=%d", eno),
- entry("RC=%d", r));
+ error("Failed to set timerfd, errno: {ERRNO}, rc: {RC}", "ERRNO", eno,
+ "RC", r);
throw std::system_error(eno, std::system_category());
}
@@ -153,8 +154,8 @@
if (r < 0)
{
auto eno = errno;
- log<level::ERR>("Failed to add event", entry("ERRNO=%d", eno),
- entry("RC=%d", r));
+ error("Failed to add event, errno: {ERRNO}, rc: {RC}", "ERRNO", eno,
+ "RC", r);
throw std::system_error(eno, std::system_category());
}
timeChangeEventSource.reset(es);
@@ -180,8 +181,8 @@
if (schedTime == 0)
{
- log<level::DEBUG>("handleTimeUpdates: The function Scheduled Host "
- "Transition is disabled.");
+ debug("handleTimeUpdates: The function Scheduled Host Transition is "
+ "disabled.");
return;
}
@@ -213,7 +214,7 @@
while (read(fd, time.data(), time.max_size()) > 0)
;
- log<level::DEBUG>("BMC system time is changed");
+ debug("BMC system time is changed");
schedHostTran->handleTimeUpdates();
return 0;
@@ -246,7 +247,7 @@
}
catch (std::exception& e)
{
- log<level::ERR>(e.what());
+ error("deserialize exception: {ERROR}", "ERROR", e);
fs::remove(path);
}
diff --git a/scheduled_host_transition.hpp b/scheduled_host_transition.hpp
index 4b75ad3..3e24f89 100644
--- a/scheduled_host_transition.hpp
+++ b/scheduled_host_transition.hpp
@@ -2,7 +2,6 @@
#include "config.h"
-#include <phosphor-logging/log.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>
#include <sdeventplus/utility/timer.hpp>
diff --git a/settings.cpp b/settings.cpp
index 9a7879a..ff5d36f 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -3,12 +3,14 @@
#include "xyz/openbmc_project/Common/error.hpp"
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
namespace settings
{
+PHOSPHOR_LOG2_USING;
+
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
@@ -38,14 +40,13 @@
response.read(result);
if (result.empty())
{
- log<level::ERR>("Invalid response from mapper");
+ error("Invalid response from mapper");
elog<InternalFailure>();
}
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in mapper GetSubTree",
- entry("ERROR=%s", e.what()));
+ error("Error in mapper GetSubTree: {ERROR}", "ERROR", e);
elog<InternalFailure>();
}
@@ -113,14 +114,13 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in mapper GetObject",
- entry("ERROR=%s", e.what()));
+ error("Error in mapper GetObject: {ERROR}", "ERROR", e);
elog<InternalFailure>();
}
if (result.empty())
{
- log<level::ERR>("Invalid response from mapper");
+ error("Invalid response from mapper");
elog<InternalFailure>();
}
diff --git a/systemd_target_monitor.cpp b/systemd_target_monitor.cpp
index d5e7a38..cc13711 100644
--- a/systemd_target_monitor.cpp
+++ b/systemd_target_monitor.cpp
@@ -2,15 +2,14 @@
#include "systemd_target_signal.hpp"
#include <CLI/CLI.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>
#include <iostream>
#include <vector>
-using phosphor::logging::level;
-using phosphor::logging::log;
+PHOSPHOR_LOG2_USING;
bool gVerbose = false;
@@ -54,7 +53,7 @@
if (filePaths.empty())
{
- log<level::ERR>("No input files");
+ error("No input files");
print_usage();
exit(-1);
}
@@ -63,7 +62,7 @@
if (targetData.size() == 0)
{
- log<level::ERR>("Invalid input files, no targets found");
+ error("Invalid input files, no targets found");
print_usage();
exit(-1);
}
diff --git a/systemd_target_signal.cpp b/systemd_target_signal.cpp
index 032722b..79ac933 100644
--- a/systemd_target_signal.cpp
+++ b/systemd_target_signal.cpp
@@ -1,7 +1,7 @@
#include "systemd_target_signal.hpp"
#include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/exception.hpp>
#include <sdbusplus/server/manager.hpp>
#include <sdeventplus/event.hpp>
@@ -15,19 +15,18 @@
{
using phosphor::logging::elog;
-using phosphor::logging::entry;
-using phosphor::logging::level;
-using phosphor::logging::log;
+PHOSPHOR_LOG2_USING;
+
using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
-void SystemdTargetLogging::logError(const std::string& error,
+void SystemdTargetLogging::logError(const std::string& errorLog,
const std::string& result)
{
auto method = this->bus.new_method_call(
"xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
"xyz.openbmc_project.Logging.Create", "Create");
// Signature is ssa{ss}
- method.append(error);
+ method.append(errorLog);
method.append("xyz.openbmc_project.Logging.Entry.Level.Critical");
method.append(std::array<std::pair<std::string, std::string>, 1>(
{std::pair<std::string, std::string>({"SYSTEMD_RESULT", result})}));
@@ -37,10 +36,9 @@
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Failed to create systemd target error",
- entry("ERROR=%s", error.c_str()),
- entry("RESULT=%s", result.c_str()),
- entry("SDBUSERR=%s", e.what()));
+ error("Failed to create systemd target error, error:{ERROR_MSG}, "
+ "result:{RESULT}, exception:{ERROR}",
+ "ERROR_MSG", errorLog, "RESULT", result, "ERROR", e);
}
}
@@ -55,9 +53,9 @@
targetEntry->second.errorsToMonitor.end(),
result) != targetEntry->second.errorsToMonitor.end())
{
- log<level::INFO>("Monitored systemd unit has hit an error",
- entry("UNIT=%s", unit.c_str()),
- entry("RESULT=%s", result.c_str()));
+ info("Monitored systemd unit has hit an error, unit:{UNIT}, "
+ "result:{RESULT}",
+ "UNIT", unit, "RESULT", result);
return (&targetEntry->second.errorToLog);
}
}
@@ -99,7 +97,7 @@
// Looking for systemd to be on dbus so we can call it
if (name == "org.freedesktop.systemd1")
{
- log<level::INFO>("org.freedesktop.systemd1 is now on dbus");
+ info("org.freedesktop.systemd1 is now on dbus");
subscribeToSystemdSignals();
}
return;
@@ -123,12 +121,12 @@
const std::string noDbus("org.freedesktop.DBus.Error.ServiceUnknown");
if (noDbus == e.name())
{
- log<level::INFO>("org.freedesktop.systemd1 not on dbus yet");
+ info("org.freedesktop.systemd1 not on dbus yet");
}
else
{
- log<level::ERR>("Failed to subscribe to systemd signals",
- entry("SDBUSERR=%s", e.what()));
+ error("Failed to subscribe to systemd signals: {ERROR}", "ERROR",
+ e);
elog<InternalFailure>();
}
return;
diff --git a/utils.cpp b/utils.cpp
index 97255e6..de1ae4b 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -1,6 +1,6 @@
#include "utils.hpp"
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
namespace phosphor
{
@@ -11,7 +11,7 @@
namespace utils
{
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
@@ -36,17 +36,17 @@
mapperResponseMsg.read(mapperResponse);
if (mapperResponse.empty())
{
- log<level::ERR>("Error no matching service",
- entry("PATH=%s", path.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ error("Error no matching service with path {PATH} and interface "
+ "{INTERFACE}",
+ "PATH", path, "INTERFACE", interface);
throw std::runtime_error("Error no matching service");
}
}
catch (const sdbusplus::exception::exception& e)
{
- log<level::ERR>("Error in mapper call", entry("ERROR=%s", e.what()),
- entry("PATH=%s", path.c_str()),
- entry("INTERFACE=%s", interface.c_str()));
+ error("Error in mapper call with path {PATH}, interface "
+ "{INTERFACE}, and exception {ERROR}",
+ "PATH", path, "INTERFACE", interface, "ERROR", e);
throw;
}