logging: replace direct journal calls with lg2
Tested:
Created a bogus journal message equivalent to the one in
TachSensor.hpp as the first line of 'main' in FanMain.cpp:
```
auto device = "FooBar";
auto msg = "OpenBMC.0.1.FanInserted";
lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg,
"REDFISH_MESSAGE_ARGS", device);
```
Observed the following in the journal:
```
{
"_MACHINE_ID" : "115e76f3bc47411eb0f20075b13444e9",
"_CMDLINE" : "/usr/bin/fansensor",
"REDFISH_MESSAGE_ID" : "OpenBMC.0.1.FanInserted",
"CODE_LINE" : "463",
"_COMM" : "fansensor",
"_EXE" : "/usr/bin/fansensor",
"_SOURCE_REALTIME_TIMESTAMP" : "33256618",
"__MONOTONIC_TIMESTAMP" : "33256849",
"SYSLOG_IDENTIFIER" : "fansensor",
"PRIORITY" : "3",
"_CAP_EFFECTIVE" : "1ffffffffff",
"_PID" : "296",
"_UID" : "0",
"_SYSTEMD_UNIT" : "xyz.openbmc_project.fansensor.service",
"REDFISH_MESSAGE_ARGS" : "FooBar",
"__REALTIME_TIMESTAMP" : "33256822",
"LOG2_FMTMSG" : "Fan Inserted",
"_SYSTEMD_CGROUP" : "/system.slice/xyz.openbmc_project.fansensor.service",
"_GID" : "0",
"_TRANSPORT" : "journal",
"__CURSOR" : "s=039afc05fc934fe08b77dd73c4092591;i=1ff;b=5ad25f16b9bd424ebe72cf30558fcdc2;m=1fb7591;t=1fb7576;x=617adeeaf1da9edc",
"CODE_FILE" : "../../../../../../../../sync/openbmc-sources/dbus-sensors/src/FanMain.cpp",
"_SYSTEMD_INVOCATION_ID" : "9eef21c4b7784ba2aa2628f162079cd3",
"CODE_FUNC" : "int main()",
"MESSAGE" : "Fan Inserted",
"_HOSTNAME" : "bletchley",
"_SYSTEMD_SLICE" : "system.slice",
"_BOOT_ID" : "5ad25f16b9bd424ebe72cf30558fcdc2"
}
```
Observed the following in /var/log/redfish:
```
1970-01-01T00:00:27.345477+00:00 OpenBMC.0.1.FanInserted,FooBar
```
Observed the following in Redfish:
```
{
"@odata.id": "/redfish/v1/Systems/system/LogServices/EventLog/Entries/27",
"@odata.type": "#LogEntry.v1_4_0.LogEntry",
"Created": "1970-01-01T00:00:27+00:00",
"EntryType": "Event",
"Id": "27",
"Message": "FooBar inserted.",
"MessageArgs": [
"FooBar"
],
"MessageId": "OpenBMC.0.1.FanInserted",
"Name": "System Event Log Entry",
"Severity": "OK"
}
```
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ib408e97ff99863cd91bcbcb43a4738d773f4e21c
diff --git a/include/TachSensor.hpp b/include/TachSensor.hpp
index e719293..344e518 100644
--- a/include/TachSensor.hpp
+++ b/include/TachSensor.hpp
@@ -1,11 +1,10 @@
#pragma once
-#include <systemd/sd-journal.h>
-
#include <Thresholds.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <gpiod.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sensor.hpp>
@@ -94,28 +93,26 @@
inline void logFanInserted(const std::string& device)
{
- sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR,
- "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanInserted",
- "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
+ auto msg = "OpenBMC.0.1.FanInserted";
+ lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg,
+ "REDFISH_MESSAGE_ARGS", device);
}
inline void logFanRemoved(const std::string& device)
{
- sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR,
- "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRemoved",
- "REDFISH_MESSAGE_ARGS=%s", device.c_str(), NULL);
+ auto msg = "OpenBMC.0.1.FanRemoved";
+ lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg, "REDFISH_MESSAGE_ARGS",
+ device);
}
inline void logFanRedundancyLost(void)
{
- sd_journal_send("MESSAGE=%s", "Fan Inserted", "PRIORITY=%i", LOG_ERR,
- "REDFISH_MESSAGE_ID=%s", "OpenBMC.0.1.FanRedundancyLost",
- NULL);
+ auto msg = "OpenBMC.0.1.FanRedundancyLost";
+ lg2::error("Fan Inserted", "REDFISH_MESSAGE_ID", msg);
}
inline void logFanRedundancyRestored(void)
{
- sd_journal_send("MESSAGE=%s", "Fan Removed", "PRIORITY=%i", LOG_ERR,
- "REDFISH_MESSAGE_ID=%s",
- "OpenBMC.0.1.FanRedundancyRegained", NULL);
+ auto msg = "OpenBMC.0.1.FanRedundancyRegained";
+ lg2::error("Fan Removed", "REDFISH_MESSAGE_ID", msg);
}
diff --git a/meson.build b/meson.build
index 0548596..48dce71 100644
--- a/meson.build
+++ b/meson.build
@@ -67,6 +67,7 @@
default_deps = [
nlohmann_json,
+ phosphor_logging_dep,
sdbusplus,
]
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index ad4794a..85fe3e5 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -14,13 +14,12 @@
// limitations under the License.
*/
-#include <systemd/sd-journal.h>
-
#include <ChassisIntrusionSensor.hpp>
#include <Utils.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/container/flat_map.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
#include <sdbusplus/asio/sd_event.hpp>
@@ -309,18 +308,15 @@
if (oldLanConnected != newLanConnected)
{
std::string strEthNum = "eth" + std::to_string(ethNum) + lanInfo;
- std::string strEvent = strEthNum + " LAN leash " +
- (newLanConnected ? "connected" : "lost");
- std::string strMsgId =
+ auto strState = newLanConnected ? "connected" : "lost";
+ auto strMsgId =
newLanConnected ? "OpenBMC.0.1.LanRegained" : "OpenBMC.0.1.LanLost";
- sd_journal_send("MESSAGE=%s", strEvent.c_str(), "PRIORITY=%i", LOG_INFO,
- "REDFISH_MESSAGE_ID=%s", strMsgId.c_str(),
- "REDFISH_MESSAGE_ARGS=%s", strEthNum.c_str(), NULL);
+
+ lg2::info("{ETHDEV} LAN leash {STATE}", "ETHDEV", strEthNum, "STATE",
+ strState, "REDFISH_MESSAGE_ID", strMsgId,
+ "REDFISH_MESSAGE_ARGS", strEthNum);
+
lanStatusMap[ethNum] = newLanConnected;
- if (debugLanLeash)
- {
- std::cout << "log redfish event: " << strEvent << "\n";
- }
}
}
diff --git a/src/PSUEvent.cpp b/src/PSUEvent.cpp
index 23021d9..b02816f 100644
--- a/src/PSUEvent.cpp
+++ b/src/PSUEvent.cpp
@@ -14,13 +14,12 @@
// limitations under the License.
*/
-#include <systemd/sd-journal.h>
-
#include <PSUEvent.hpp>
#include <SensorPaths.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/container/flat_map.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/asio/object_server.hpp>
@@ -319,22 +318,18 @@
if (!deassertMessage.empty())
{
// Fan Failed has two args
- std::string sendMessage = eventName + " deassert";
if (deassertMessage == "OpenBMC.0.1.PowerSupplyFanRecovered")
{
- sd_journal_send(
- "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
- LOG_INFO, "REDFISH_MESSAGE_ID=%s",
- deassertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s,%s",
- psuName.c_str(), fanName.c_str(), NULL);
+ lg2::info("{EVENT} deassert", "EVENT", eventName,
+ "REDFISH_MESSAGE_ID", deassertMessage,
+ "REDFISH_MESSAGE_ARGS",
+ (psuName + ',' + fanName));
}
else
{
- sd_journal_send(
- "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
- LOG_INFO, "REDFISH_MESSAGE_ID=%s",
- deassertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s",
- psuName.c_str(), NULL);
+ lg2::info("{EVENT} deassert", "EVENT", eventName,
+ "REDFISH_MESSAGE_ID", deassertMessage,
+ "REDFISH_MESSAGE_ARGS", psuName);
}
}
@@ -363,22 +358,18 @@
}
// Fan Failed has two args
- std::string sendMessage = eventName + " assert";
if (assertMessage == "OpenBMC.0.1.PowerSupplyFanFailed")
{
- sd_journal_send(
- "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
- LOG_WARNING, "REDFISH_MESSAGE_ID=%s",
- assertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s,%s",
- psuName.c_str(), fanName.c_str(), NULL);
+ lg2::warning("{EVENT} assert", "EVENT", eventName,
+ "REDFISH_MESSAGE_ID", assertMessage,
+ "REDFISH_MESSAGE_ARGS",
+ (psuName + ',' + fanName));
}
else
{
- sd_journal_send(
- "MESSAGE=%s", sendMessage.c_str(), "PRIORITY=%i",
- LOG_WARNING, "REDFISH_MESSAGE_ID=%s",
- assertMessage.c_str(), "REDFISH_MESSAGE_ARGS=%s",
- psuName.c_str(), NULL);
+ lg2::warning("{EVENT} assert", "EVENT", eventName,
+ "REDFISH_MESSAGE_ID", assertMessage,
+ "REDFISH_MESSAGE_ARGS", psuName);
}
}
if ((*combineEvent).empty())