diff options
author | Marri Devender Rao <devenrao@in.ibm.com> | 2017-04-04 03:43:00 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-04-12 20:54:46 +0000 |
commit | 7d0a07ba3205807b5c2f5c84261d7a9cc295decb (patch) | |
tree | 6f27e0f73485cf5fb90db1ea947ccd8766bcd891 /phosphor-logging | |
parent | 8110ca6d243bbec89e5ce3be644883bf0dadd23d (diff) | |
download | phosphor-logging-7d0a07ba3205807b5c2f5c84261d7a9cc295decb.tar.gz phosphor-logging-7d0a07ba3205807b5c2f5c84261d7a9cc295decb.zip |
Add new commit API and deprecate older commit method
Added new commit method that accepts an sdbusplus exception
Deprecate commit which accepts an exception name
Change-Id: I9b5c91eb13466eb576c329ebb7fd00ce33f7dd9f
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
Diffstat (limited to 'phosphor-logging')
-rw-r--r-- | phosphor-logging/elog-errors-HostEvent.hpp | 22 | ||||
-rw-r--r-- | phosphor-logging/elog.hpp | 37 |
2 files changed, 52 insertions, 7 deletions
diff --git a/phosphor-logging/elog-errors-HostEvent.hpp b/phosphor-logging/elog-errors-HostEvent.hpp index 0efb328..89b3f55 100644 --- a/phosphor-logging/elog-errors-HostEvent.hpp +++ b/phosphor-logging/elog-errors-HostEvent.hpp @@ -7,6 +7,7 @@ #include <tuple> #include <type_traits> #include <vector> +#include <sdbusplus/exception.hpp> #include <phosphor-logging/log.hpp> namespace phosphor @@ -44,13 +45,28 @@ struct ESEL } // namespace _Event -struct Event +struct Event : public sdbusplus::exception_t { - static constexpr auto err_code = "org.open_power.Error.Host.Event.Event"; - static constexpr auto err_msg = "A host system event was received"; + static constexpr auto errName = "org.open_power.Error.Host.Event.Event"; + static constexpr auto errDesc = "A host system event was received"; static constexpr auto L = level::INFO; using ESEL = _Event::ESEL; using metadata_types = std::tuple<ESEL>; + const char* name() const noexcept + { + return errName; + } + + const char* description() const noexcept + { + return errDesc; + } + + const char* what() const noexcept + { + return errName; + } + }; } // namespace Host } // namespace Error diff --git a/phosphor-logging/elog.hpp b/phosphor-logging/elog.hpp index 329dc0d..eec5679 100644 --- a/phosphor-logging/elog.hpp +++ b/phosphor-logging/elog.hpp @@ -1,9 +1,8 @@ #pragma once - #include <tuple> #include <utility> #include <phosphor-logging/log.hpp> - +#include <sdbusplus/exception.hpp> namespace phosphor { @@ -84,15 +83,39 @@ struct map_exception_type template <typename T> using map_exception_type_t = typename map_exception_type<T>::type; +/** @fn commit() + * @brief Create an error log entry based on journal + * entry with a specified exception name + * @param[in] name - name of the error exception + */ +void commit(const char* name); + } // namespace details /** @fn commit() + * \deprecated use commit<T>() * @brief Create an error log entry based on journal * entry with a specified MSG_ID - * @param[in] - Exception name + * @param[in] name - name of the error exception */ void commit(std::string&& name); +/** @fn commit() + * @brief Create an error log entry based on journal + * entry with a specified MSG_ID + */ +template <typename T> +void 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(details::map_exception_type_t<T>::errName); +} + + /** @fn elog() * @brief Create a journal log entry based on predefined * error log information @@ -102,6 +125,12 @@ void commit(std::string&& name); template <typename T, typename ...Args> void elog(Args... i_args) { + // 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" + ); + // Validate the caller passed in the required parameters static_assert(std::is_same<typename details:: map_exception_type_t<T>::metadata_types, @@ -111,7 +140,7 @@ void elog(Args... i_args) "You are not passing in required arguments for this error"); log<details::map_exception_type_t<T>::L>( - details::map_exception_type_t<T>::err_msg, + T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...); // Now throw an exception for this error |