diff options
-rw-r--r-- | elog_entry.hpp | 23 | ||||
-rw-r--r-- | log_manager.cpp | 18 | ||||
-rw-r--r-- | log_manager.hpp | 10 | ||||
-rw-r--r-- | log_manager_main.cpp | 3 |
4 files changed, 45 insertions, 9 deletions
diff --git a/elog_entry.hpp b/elog_entry.hpp index bd3915c..92360cb 100644 --- a/elog_entry.hpp +++ b/elog_entry.hpp @@ -35,11 +35,30 @@ class Entry : public details::ServerObject<details::EntryIface> virtual ~Entry() = default; /** @brief Constructor to put object onto bus at a dbus path. + * Defer signal registration (pass true for deferSignal to the + * base class) until after the properties are set. * @param[in] bus - Bus to attach to. * @param[in] path - Path to attach at. + * @param[in] properties - Desired Entry properties. */ - Entry(sdbusplus::bus::bus& bus, const char* path) : - details::ServerObject<details::EntryIface>(bus, path) {}; + Entry(sdbusplus::bus::bus& bus, + const std::string& path, + uint32_t idErr, + Level severityErr, + std::string&& msgErr, + std::vector<std::string>&& additionalDataErr) : + details::ServerObject<details::EntryIface> + (bus, path.c_str(), true) + { + id(idErr); + severity(severityErr); + message(std::move(msgErr)); + additionalData(std::move(additionalDataErr)); + + // Emit deferred signal. + this->emit_object_added(); + }; + }; } // namespace logging diff --git a/log_manager.cpp b/log_manager.cpp index c9edd7e..e9f11ec 100644 --- a/log_manager.cpp +++ b/log_manager.cpp @@ -7,6 +7,8 @@ #include <systemd/sd-bus.h> #include <systemd/sd-journal.h> #include "elog-lookup.cpp" +#include "config.h" +#include "elog_entry.hpp" #include "log.hpp" #include "log_manager.hpp" @@ -21,7 +23,6 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) constexpr const auto path = "/tmp/elog"; constexpr const auto transactionIdVar = "TRANSACTION_ID"; - // Create log file std::string filename{}; filename.append(path); // TODO Create error logs in their own separate dir once permanent location @@ -41,6 +42,7 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) std::string transactionIdStr = std::to_string(transactionId); std::vector<std::string> metalist = g_errMetaMap[errMsg]; + std::vector<std::string> additionalData; // 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. @@ -78,6 +80,7 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) { continue; } + efile << "\t\"@" << data << "\"," << std::endl; // Search for the metadata variables in the current journal entry @@ -94,6 +97,7 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) } // Metatdata variable found, write to file + additionalData.push_back(std::string(data)); efile << "\t\"@" << data << "\"," << std::endl; } efile << "\t}" << std::endl; @@ -104,6 +108,18 @@ void Manager::commit(uint64_t transactionId, std::string errMsg) } sd_journal_close(j); + // Create error Entry dbus object + entryId++; + auto objPath = std::string(OBJ_ENTRY) + '/' + + std::to_string(entryId); + entries.insert(std::make_pair(entryId, std::make_unique<Entry>( + busLog, + objPath, + entryId, + (Entry::Level)g_errLevelMap[errMsg], + std::move(errMsg), + std::move(additionalData)))); + efile << "}" << std::endl; efile.close(); return; diff --git a/log_manager.hpp b/log_manager.hpp index 4ad0ced..43070ff 100644 --- a/log_manager.hpp +++ b/log_manager.hpp @@ -38,9 +38,10 @@ class Manager : public details::ServerObject<details::ManagerIface> * @param[in] bus - Bus to attach to. * @param[in] path - Path to attach at. */ - Manager(sdbusplus::bus::bus& bus, const char* path) : - details::ServerObject<details::ManagerIface>(bus, path), - busLog(bus) {}; + Manager(sdbusplus::bus::bus& bus, const char* objPath) : + details::ServerObject<details::ManagerIface>(bus, objPath), + busLog(bus), + entryId(0) {}; /* * @fn commit() @@ -61,6 +62,9 @@ class Manager : public details::ServerObject<details::ManagerIface> /** @brief Persistent map of Entry dbus objects and their ID */ std::map<uint32_t, std::unique_ptr<Entry>> entries; + + /** @brief Id of last error log entry */ + uint32_t entryId; }; } // namespace logging diff --git a/log_manager_main.cpp b/log_manager_main.cpp index 10b6e76..2d3ccf3 100644 --- a/log_manager_main.cpp +++ b/log_manager_main.cpp @@ -14,9 +14,6 @@ int main(int argc, char *argv[]) bus.request_name(BUSNAME_LOGGING); - // TODO Create error log dbus object on demand, when the Commit interface - // creates an error log it'd call this entry interface to create an object. - while(true) { bus.process_discard(); |