diff options
Diffstat (limited to 'phosphor-logging/elog.hpp')
-rw-r--r-- | phosphor-logging/elog.hpp | 110 |
1 files changed, 47 insertions, 63 deletions
diff --git a/phosphor-logging/elog.hpp b/phosphor-logging/elog.hpp index b76bd6c..5aace07 100644 --- a/phosphor-logging/elog.hpp +++ b/phosphor-logging/elog.hpp @@ -1,9 +1,10 @@ #pragma once -#include <tuple> -#include <utility> +#include "xyz/openbmc_project/Logging/Entry/server.hpp" + #include <phosphor-logging/log.hpp> #include <sdbusplus/exception.hpp> -#include "xyz/openbmc_project/Logging/Entry/server.hpp" +#include <tuple> +#include <utility> namespace phosphor { @@ -16,15 +17,13 @@ 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. -*/ + */ template <typename T> struct prev_entry { using type = T; }; - - namespace details { /** @@ -40,7 +39,10 @@ struct deduce_entry_type { using type = T; - auto get() { return value._entry; } + auto get() + { + return value._entry; + } T value; }; @@ -56,7 +58,10 @@ template <typename T> struct deduce_entry_type<prev_entry<T>> { using type = T; - auto get() { return std::make_tuple(); } + auto get() + { + return std::make_tuple(); + } prev_entry<T> value; }; @@ -64,8 +69,8 @@ struct deduce_entry_type<prev_entry<T>> /** * @brief Typedef for above structure usage */ -template <typename T> using deduce_entry_type_t = - typename deduce_entry_type<T>::type; +template <typename T> +using deduce_entry_type_t = typename deduce_entry_type<T>::type; /** * @brief Used to map an sdbusplus error to a phosphor-logging error type @@ -84,8 +89,8 @@ struct map_exception_type /** * @brief Typedef for above structure usage */ -template <typename T> using map_exception_type_t = - typename map_exception_type<T>::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 @@ -116,10 +121,8 @@ 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" - ); + static_assert(std::is_base_of<sdbusplus::exception::exception, T>::value, + "T must be a descendant of sdbusplus::exception::exception"); details::commit(T::errName); } @@ -132,40 +135,32 @@ 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" - ); + 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 * error log information * @tparam T - Error log type * @param[in] i_args - Metadata fields to be added to the journal entry */ -template <typename T, typename ...Args> +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" - ); + 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"); + 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()...); + T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...); // Now throw an exception for this error throw T(); @@ -177,26 +172,21 @@ void elog(Args... i_args) * @tparam T - exception * @param[in] i_args - Metadata fields to be added to the journal entry */ -template <typename T, typename ...Args> +template <typename T, typename... Args> void report(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 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"); + 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()...); + T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...); commit<T>(); } @@ -209,26 +199,21 @@ void report(Args... i_args) * @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> +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 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"); + 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()...); + T::errDesc, details::deduce_entry_type<Args>{i_args}.get()...); commit<T>(level); } @@ -236,4 +221,3 @@ void report(Entry::Level level, Args... i_args) } // namespace logging } // namespace phosphor - |