Return entryID on commiting logs

Let the Commit()/CommitWithLvl() methods return entryID, so that the
caller of commit()/report() could get the entryID directly without
querying the logging service again.

This is useful in cases that the caller needs to know the entryID of the
commit()/report() events.

Tested: Manually verify the report() returns the correct entryID.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Ieb22d32d4e9242ec46b799f6e98ca3d49e7590b9
diff --git a/elog.cpp b/elog.cpp
index 012006e..890fd5d 100644
--- a/elog.cpp
+++ b/elog.cpp
@@ -26,29 +26,35 @@
     return m;
 }
 
-void commit(const char* name)
+uint32_t commit(const char* name)
 {
     auto msg = _prepareMsg("Commit");
     uint64_t id = sdbusplus::server::transaction::get_id();
     msg.append(id, name);
     auto bus = sdbusplus::bus::new_default();
-    bus.call_noreply(msg);
+    auto reply = bus.call(msg);
+    uint32_t entryID;
+    reply.read(entryID);
+    return entryID;
 }
 
-void commit(const char* name, Entry::Level level)
+uint32_t commit(const char* name, Entry::Level level)
 {
     auto msg = _prepareMsg("CommitWithLvl");
     uint64_t id = sdbusplus::server::transaction::get_id();
     msg.append(id, name, static_cast<uint32_t>(level));
     auto bus = sdbusplus::bus::new_default();
-    bus.call_noreply(msg);
+    auto reply = bus.call(msg);
+    uint32_t entryID;
+    reply.read(entryID);
+    return entryID;
 }
 } // namespace details
 
-void commit(std::string&& name)
+uint32_t commit(std::string&& name)
 {
     log<level::ERR>("method is deprecated, use commit() with exception type");
-    phosphor::logging::details::commit(name.c_str());
+    return phosphor::logging::details::commit(name.c_str());
 }
 
 } // namespace logging
diff --git a/log_manager.cpp b/log_manager.cpp
index 756ee4f..8fca0a9 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -66,17 +66,19 @@
     return infoErrors.size();
 }
 
-void Manager::commit(uint64_t transactionId, std::string errMsg)
+uint32_t Manager::commit(uint64_t transactionId, std::string errMsg)
 {
     auto level = getLevel(errMsg);
     _commit(transactionId, std::move(errMsg), level);
+    return entryId;
 }
 
-void Manager::commitWithLvl(uint64_t transactionId, std::string errMsg,
-                            uint32_t errLvl)
+uint32_t Manager::commitWithLvl(uint64_t transactionId, std::string errMsg,
+                                uint32_t errLvl)
 {
     _commit(transactionId, std::move(errMsg),
             static_cast<Entry::Level>(errLvl));
+    return entryId;
 }
 
 void Manager::_commit(uint64_t transactionId, std::string&& errMsg,
diff --git a/log_manager.hpp b/log_manager.hpp
index 7437f4e..e04c6b7 100644
--- a/log_manager.hpp
+++ b/log_manager.hpp
@@ -79,7 +79,7 @@
      * @param[in] errMsg - The error exception message associated with the
      *                     error log to be committed.
      */
-    void commit(uint64_t transactionId, std::string errMsg) override;
+    uint32_t commit(uint64_t transactionId, std::string errMsg) override;
 
     /*
      * @fn commit()
@@ -92,8 +92,8 @@
      *                     error log to be committed.
      * @param[in] errLvl - level of the error
      */
-    void commitWithLvl(uint64_t transactionId, std::string errMsg,
-                       uint32_t errLvl) override;
+    uint32_t commitWithLvl(uint64_t transactionId, std::string errMsg,
+                           uint32_t errLvl) override;
 
     /** @brief Erase specified entry d-bus object
      *
diff --git a/phosphor-logging/elog.hpp b/phosphor-logging/elog.hpp
index 365080c..83f35e7 100644
--- a/phosphor-logging/elog.hpp
+++ b/phosphor-logging/elog.hpp
@@ -96,12 +96,16 @@
  *  @brief Create an error log entry based on journal
  *          entry with a specified exception name
  *  @param[in] name - name of the error exception
+ *
+ *  @return The entry ID
  */
-void commit(const char* name);
+uint32_t commit(const char* name);
 
 /** @fn commit() - override that accepts error level
+ *
+ *  @return The entry ID
  */
-void commit(const char* name, Entry::Level level);
+uint32_t commit(const char* name, Entry::Level level);
 
 } // namespace details
 
@@ -110,34 +114,40 @@
  *  @brief Create an error log entry based on journal
  *          entry with a specified MSG_ID
  *  @param[in] name - name of the error exception
+ *
+ *  @return The entry ID
  */
-void commit(std::string&& name);
+uint32_t commit(std::string&& name);
 
 /** @fn commit()
  *  @brief Create an error log entry based on journal
  *          entry with a specified MSG_ID
+ *
+ *  @return The entry ID
  */
 template <typename T>
-void commit()
+uint32_t commit()
 {
     // Validate if the exception is derived from sdbusplus::exception.
     static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                   "T must be a descendant of sdbusplus::exception::exception");
-    details::commit(T::errName);
+    return details::commit(T::errName);
 }
 
 /** @fn commit()
  *  @brief Create an error log entry based on journal
  *         entry with a specified MSG_ID. This override accepts error level.
  *  @param[in] level - level of the error
+ *
+ *  @return The entry ID
  */
 template <typename T>
-void commit(Entry::Level level)
+uint32_t commit(Entry::Level level)
 {
     // Validate if the exception is derived from sdbusplus::exception.
     static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
                   "T must be a descendant of sdbusplus::exception::exception");
-    details::commit(T::errName, level);
+    return details::commit(T::errName, level);
 }
 
 /** @fn elog()
@@ -171,9 +181,11 @@
  *         error log information and commit the error
  *  @tparam T - exception
  *  @param[in] i_args - Metadata fields to be added to the journal entry
+ *
+ *  @return The entry ID
  */
 template <typename T, typename... Args>
-void report(Args... i_args)
+uint32_t report(Args... i_args)
 {
     // validate if the exception is derived from sdbusplus::exception.
     static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
@@ -188,7 +200,7 @@
     log<details::map_exception_type_t<T>::L>(
         T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...);
 
-    commit<T>();
+    return commit<T>();
 }
 
 /** @fn report()
@@ -198,9 +210,11 @@
  *  @tparam T - exception
  *  @param[in] level - level of the error
  *  @param[in] i_args - Metadata fields to be added to the journal entry
+ *
+ *  @return The entry ID
  */
 template <typename T, typename... Args>
-void report(Entry::Level level, Args... i_args)
+uint32_t report(Entry::Level level, Args... i_args)
 {
     // validate if the exception is derived from sdbusplus::exception.
     static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value,
@@ -215,7 +229,7 @@
     log<details::map_exception_type_t<T>::L>(
         T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...);
 
-    commit<T>(level);
+    return commit<T>(level);
 }
 
 } // namespace logging
diff --git a/xyz/openbmc_project/Logging/Internal/Manager.interface.yaml b/xyz/openbmc_project/Logging/Internal/Manager.interface.yaml
index 4c1c8ce..6ab85c5 100644
--- a/xyz/openbmc_project/Logging/Internal/Manager.interface.yaml
+++ b/xyz/openbmc_project/Logging/Internal/Manager.interface.yaml
@@ -18,6 +18,11 @@
           description: >
               The error exception message associated with the error
               event log to be committed.
+      returns:
+        - name: entryID
+          type: uint32
+          description: >
+            The ID of the entry.
     - name: CommitWithLvl
       description: >
           Write the requested error/event entry with its associated metadata
@@ -37,3 +42,8 @@
           type: uint32
           description: >
               The error level/severity indicator.
+      returns:
+        - name: entryID
+          type: uint32
+          description: >
+            The ID of the entry.