diff options
Diffstat (limited to 'phosphor-logging/elog.hpp')
-rw-r--r-- | phosphor-logging/elog.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/phosphor-logging/elog.hpp b/phosphor-logging/elog.hpp index 8a6b9c1..b76bd6c 100644 --- a/phosphor-logging/elog.hpp +++ b/phosphor-logging/elog.hpp @@ -3,12 +3,16 @@ #include <utility> #include <phosphor-logging/log.hpp> #include <sdbusplus/exception.hpp> +#include "xyz/openbmc_project/Logging/Entry/server.hpp" + namespace phosphor { namespace logging { +using namespace sdbusplus::xyz::openbmc_project::Logging::server; + /** * @brief Structure used by callers to indicate they want to use the last value * put in the journal for input parameter. @@ -90,6 +94,10 @@ template <typename T> using map_exception_type_t = */ void commit(const char* name); +/** @fn commit() - override that accepts error level + */ +void commit(const char* name, Entry::Level level); + } // namespace details /** @fn commit() @@ -115,6 +123,22 @@ void commit() 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 + */ +template <typename T> +void 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); +} + /** @fn elog() * @brief Create a journal log entry based on predefined @@ -176,6 +200,39 @@ void report(Args... i_args) commit<T>(); } + +/** @fn report() + * @brief Create a journal log entry based on predefined + * error log information and commit the error. Accepts error + * level. + * @tparam T - exception + * @param[in] level - level of the error + * @param[in] i_args - Metadata fields to be added to the journal entry + */ +template <typename T, typename ...Args> +void 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, + "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, + std::tuple< + details::deduce_entry_type_t<Args>...>> + ::value, + "You are not passing in required arguments for this error"); + + log<details::map_exception_type_t<T>::L>( + T::errDesc, + details::deduce_entry_type<Args>{i_args}.get()...); + + commit<T>(level); +} + } // namespace logging } // namespace phosphor |