summaryrefslogtreecommitdiffstats
path: root/log_manager.cpp
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2017-01-24 12:21:50 -0600
committerAdriana Kobylak <anoo@us.ibm.com>2017-01-30 12:57:24 -0600
commit7298dc2320ff8b18b16acfb66a06c328c786dd87 (patch)
tree6c33e9245d08c45d2b9ffc2d2c41a687fe0c3395 /log_manager.cpp
parent7d0692ab33bee41f2525ebd454d948fc9d351822 (diff)
downloadphosphor-logging-7298dc2320ff8b18b16acfb66a06c328c786dd87.tar.gz
phosphor-logging-7298dc2320ff8b18b16acfb66a06c328c786dd87.zip
logging: Commit: Use transaction id and metadata lookup
Add the lookup mako target to the makefile to get it built. Use the lookup map to find the metadata that needs to be added to the error log. Use the transaction id to filter for the desired journal entries. Signed-off-by: Adriana Kobylak <anoo@us.ibm.com> Change-Id: Ia57dc83aab4f7ee35f8de32a799c862be28113f7
Diffstat (limited to 'log_manager.cpp')
-rw-r--r--log_manager.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/log_manager.cpp b/log_manager.cpp
index a3e49e9..06beaa6 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -6,6 +6,7 @@
#include <sdbusplus/vtable.hpp>
#include <systemd/sd-bus.h>
#include <systemd/sd-journal.h>
+#include "elog-lookup.cpp"
#include "log.hpp"
#include "log_manager.hpp"
@@ -18,7 +19,7 @@ void Manager::commit(uint64_t transactionId, std::string errMsg)
{
// TODO Change /tmp path to a permanent location on flash
constexpr const auto path = "/tmp/elog";
- constexpr const auto msgIdStr = "_PID";
+ constexpr const auto transactionIdVar = "TRANSACTION_ID";
// Create log file
std::string filename{};
@@ -29,9 +30,6 @@ void Manager::commit(uint64_t transactionId, std::string errMsg)
efile.open(filename);
efile << "{" << std::endl;
- //const char* metaVar = nullptr;
- std::vector<const char*> metaList;
-
sd_journal *j = nullptr;
int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY);
if (rc < 0)
@@ -41,6 +39,9 @@ void Manager::commit(uint64_t transactionId, std::string errMsg)
return;
}
+ std::string transactionIdStr = std::to_string(transactionId);
+ std::vector<std::string> metalist = g_errMetaMap[errMsg];
+
// Read the journal from the end to get the most recent entry first.
// The result from the sd_journal_get_data() is of the form VARIABLE=value.
SD_JOURNAL_FOREACH_BACKWARDS(j)
@@ -48,24 +49,23 @@ void Manager::commit(uint64_t transactionId, std::string errMsg)
const char *data = nullptr;
size_t length = 0;
- // Search for the msg id
- rc = sd_journal_get_data(j, msgIdStr, (const void **)&data, &length);
+ // Look for the transaction id metadata variable
+ rc = sd_journal_get_data(j, transactionIdVar, (const void **)&data,
+ &length);
if (rc < 0)
{
- // Instance not found, continue to next journal entry
+ // This journal entry does not have the transaction id,
+ // continue to next entry
continue;
}
+
std::string result(data);
-// TODO String msgid is now an int transaction id. This piece will be
-// uncommented and reworked with the upcoming change to read the metadata
-// fields from the header file.
-#if 0
- if (result.find(msgid) == std::string::npos)
+ if (result.find(transactionIdStr) == std::string::npos)
{
- // Match not found, continue to next journal entry
+ // Requested transaction id not found,
+ // continue to next journal entry.
continue;
}
-#endif
// Match found, write to file
// TODO This is a draft format based on the redfish event logs written
// in json, the final openbmc format is to be determined
@@ -81,14 +81,15 @@ void Manager::commit(uint64_t transactionId, std::string errMsg)
efile << "\t\"@" << data << "\"," << std::endl;
// Search for the metadata variables in the current journal entry
- for (auto i : metaList)
+ for (auto metaVarStr : metalist)
{
- rc = sd_journal_get_data(j, i, (const void **)&data, &length);
+ rc = sd_journal_get_data(j, metaVarStr.c_str(),
+ (const void **)&data, &length);
if (rc < 0)
{
// Not found, continue to next metadata variable
logging::log<logging::level::INFO>("Failed to find metadata",
- logging::entry("META_FIELD=%s", i));
+ logging::entry("META_FIELD=%s", metaVarStr.c_str()));
continue;
}
@@ -136,3 +137,4 @@ void Manager::run() noexcept
} // namespace logging
} // namepsace phosphor
+
OpenPOWER on IntegriCloud