Updated Miscellaneous Journal Traces to lg2
Update the logging API used for files not in
phosphor-fan-presence/presence, phosphor-fan-presence/monitor,
or phosphor-fan-presence/control from the older phosphor::logging::log
to the more recent lg2::log.
Tested:
* Verified journal traces worked correctly in simulation and on
physical hardware.
* Modified json config files to force parsing and sensor-monitor
errors and verified correct output and key/value pairs in the
journalctl output.
Change-Id: Ie68ac5733ecd20d5f17882020df861a975121f77
Signed-off-by: Anwaar Hadi <anwaar.hadi@ibm.com>
diff --git a/sensor-monitor/alarm_timestamps.hpp b/sensor-monitor/alarm_timestamps.hpp
index b5889a9..5886dc4 100644
--- a/sensor-monitor/alarm_timestamps.hpp
+++ b/sensor-monitor/alarm_timestamps.hpp
@@ -22,12 +22,11 @@
#include <cereal/types/string.hpp>
#include <cereal/types/tuple.hpp>
#include <cereal/types/vector.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdeventplus/clock.hpp>
#include <sdeventplus/utility/timer.hpp>
#include <filesystem>
-#include <format>
#include <fstream>
#include <map>
#include <tuple>
@@ -242,13 +241,10 @@
catch (const std::exception& e)
{
// Include possible exception when removing file, otherwise ec = 0
- using namespace phosphor::logging;
std::error_code ec;
std::filesystem::remove(path, ec);
- log<level::ERR>(
- std::format("Unable to restore persisted times ({}, ec: {})",
- e.what(), ec.value())
- .c_str());
+ lg2::error("Unable to restore persisted times ({ERROR}, ec: {EC})",
+ "ERROR", e, "EC", ec.value());
}
}
diff --git a/sensor-monitor/shutdown_alarm_monitor.cpp b/sensor-monitor/shutdown_alarm_monitor.cpp
index 1cdb547..03df62d 100644
--- a/sensor-monitor/shutdown_alarm_monitor.cpp
+++ b/sensor-monitor/shutdown_alarm_monitor.cpp
@@ -19,14 +19,11 @@
#include <unistd.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Logging/Entry/server.hpp>
-#include <format>
-
namespace sensor::monitor
{
-using namespace phosphor::logging;
using namespace phosphor::fan::util;
using namespace phosphor::fan;
namespace fs = std::filesystem;
@@ -160,9 +157,8 @@
catch (const DBusServiceError& e)
{
// The sensor isn't on D-Bus anymore
- log<level::INFO>(std::format("No {} interface on {} anymore.",
- interface, sensorPath)
- .c_str());
+ lg2::info("No {INTERFACE} interface on {SENSOR_PATH} anymore.",
+ "INTERFACE", interface, "SENSOR_PATH", sensorPath);
continue;
}
@@ -281,11 +277,10 @@
{
const uint64_t& original = previousStartTime->second;
- log<level::INFO>(std::format("Found previously running {} timer "
- "for {} with start time {}",
- propertyName, sensorPath, original)
- .c_str());
-
+ lg2::info("Found previously running {PROPERTY_NAME} timer "
+ "for {SENSOR_PATH} with start time {START_TIME}",
+ "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath,
+ "START_TIME", original);
// Sanity check it isn't total garbage.
if (now > original)
{
@@ -302,19 +297,18 @@
}
else
{
- log<level::WARNING>(
- std::format(
- "Restarting {} shutdown timer for {} for full "
- "time because saved time {} is after current time {}",
- propertyName, sensorPath, original, now)
- .c_str());
+ lg2::warning(
+ "Restarting {PROPERTY_NAME} shutdown timer for {SENSOR_PATH} for full "
+ "time because saved time {SAVED_TIME} is after current time {CURRENT_TIME}",
+ "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath,
+ "SAVED_TIME", original, "CURRENT_TIME", now);
}
}
- log<level::INFO>(
- std::format("Starting {}ms {} shutdown timer due to sensor {} value {}",
- shutdownDelay.count(), propertyName, sensorPath, *value)
- .c_str());
+ lg2::info(
+ "Starting {TIME}ms {PROPERTY_NAME} shutdown timer due to sensor {SENSOR_PATH} value {VALUE}",
+ "TIME", shutdownDelay.count(), "PROPERTY_NAME", propertyName,
+ "SENSOR_PATH", sensorPath, "VALUE", *value);
auto& timer = alarm->second;
@@ -345,11 +339,10 @@
createEventLog(alarmKey, false, value);
- log<level::INFO>(
- std::format("Stopping {} shutdown timer due to sensor {} value {}",
- propertyName, sensorPath, value)
- .c_str());
-
+ lg2::info(
+ "Stopping {PROPERTY_NAME} shutdown timer due to sensor {SENSOR_PATH} value {VALUE}",
+ "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath, "VALUE",
+ value);
auto& timer = alarm->second;
timer->setEnabled(false);
timer.reset();
@@ -369,10 +362,8 @@
}
catch (const std::exception& e)
{
- auto message = std::format(
- "Caught exception while creating BMC dump: {}", e.what());
-
- log<level::ERR>(message.c_str());
+ lg2::error("Caught exception while creating BMC dump: {ERROR}", "ERROR",
+ e);
}
}
@@ -384,11 +375,9 @@
auto value = SDBusPlus::getProperty<double>(bus, sensorPath, valueInterface,
valueProperty);
- log<level::ERR>(
- std::format(
- "The {} shutdown timer expired for sensor {}, shutting down",
- propertyName, sensorPath)
- .c_str());
+ lg2::error(
+ "The {PROPERTY_NAME} shutdown timer expired for sensor {SENSOR_PATH}, shutting down",
+ "PROPERTY_NAME", propertyName, "SENSOR_PATH", sensorPath);
// Re-send the event log. If someone didn't want this it could be
// wrapped by a compile option.
diff --git a/sensor-monitor/threshold_alarm_logger.cpp b/sensor-monitor/threshold_alarm_logger.cpp
index 545f01e..54f5a8a 100644
--- a/sensor-monitor/threshold_alarm_logger.cpp
+++ b/sensor-monitor/threshold_alarm_logger.cpp
@@ -21,16 +21,13 @@
#include <unistd.h>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Logging/Entry/server.hpp>
-#include <format>
-
namespace sensor::monitor
{
using namespace sdbusplus::xyz::openbmc_project::Logging::server;
-using namespace phosphor::logging;
using namespace phosphor::fan;
using namespace phosphor::fan::util;
@@ -292,10 +289,8 @@
auto properties = it->second.find(alarmProperty);
if (properties == it->second.end())
{
- log<level::INFO>(
- std::format("Could not find {} in threshold alarms map",
- alarmProperty)
- .c_str());
+ lg2::info("Could not find {ALARM_PROPERTY} in threshold alarms map",
+ "ALARM_PROPERTY", alarmProperty);
return;
}
@@ -309,10 +304,10 @@
ad.emplace("SENSOR_VALUE", std::to_string(sensorValue));
- log<level::INFO>(
- std::format("Threshold Event {} {} = {} (sensor value {})",
- sensorPath, alarmProperty, alarmValue, sensorValue)
- .c_str());
+ lg2::info(
+ "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE} (sensor value {SENSOR_VALUE})",
+ "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+ "ALARM_VALUE", alarmValue, "SENSOR_VALUE", sensorValue);
}
catch (const DBusServiceError& e)
{
@@ -320,9 +315,10 @@
// not be in the mapper yet. This could only happen if the sensor
// application was started up after this one and the value exceeded the
// threshold immediately.
- log<level::INFO>(std::format("Threshold Event {} {} = {}", sensorPath,
- alarmProperty, alarmValue)
- .c_str());
+ lg2::info(
+ "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE}",
+ "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+ "ALARM_VALUE", alarmValue);
}
auto callout = getCallout(sensorPath);
@@ -345,16 +341,17 @@
ad.emplace("THRESHOLD_VALUE", std::to_string(thresholdValue));
- log<level::INFO>(
- std::format("Threshold Event {} {} = {} (threshold value {})",
- sensorPath, alarmProperty, alarmValue, thresholdValue)
- .c_str());
+ lg2::info(
+ "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE} (threshold value {THRESHOLD_VALUE})",
+ "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+ "ALARM_VALUE", alarmValue, "THRESHOLD_VALUE", thresholdValue);
}
catch (const DBusServiceError& e)
{
- log<level::INFO>(std::format("Threshold Event {} {} = {}", sensorPath,
- alarmProperty, alarmValue)
- .c_str());
+ lg2::info(
+ "Threshold Event {SENSOR_PATH} {ALARM_PROPERTY} = {ALARM_VALUE}",
+ "SENSOR_PATH", sensorPath, "ALARM_PROPERTY", alarmProperty,
+ "ALARM_VALUE", alarmValue);
}
type.front() = toupper(type.front());
@@ -373,10 +370,8 @@
auto pos = sensorPath.find_last_of('/');
if ((sensorPath.back() == '/') || (pos == std::string::npos))
{
- log<level::ERR>(
- std::format("Cannot get sensor name from sensor path {}",
- sensorPath)
- .c_str());
+ lg2::error("Cannot get sensor name from sensor path {SENSOR_PATH}",
+ "SENSOR_PATH", sensorPath);
return "unknown_sensor";
}
@@ -388,10 +383,8 @@
auto pos = sensorPath.find_last_of('/');
if ((sensorPath.back() == '/') || (pos == std::string::npos))
{
- log<level::ERR>(
- std::format("Cannot get sensor type from sensor path {}",
- sensorPath)
- .c_str());
+ lg2::error("Cannot get sensor type from sensor path {SENSOR_PATH}",
+ "SENSOR_PATH", sensorPath);
throw std::runtime_error("Invalid sensor path");
}