diff options
-rw-r--r-- | elog.cpp | 15 | ||||
-rw-r--r-- | phosphor-logging/elog-errors-HostEvent.hpp | 22 | ||||
-rw-r--r-- | phosphor-logging/elog.hpp | 37 | ||||
-rw-r--r-- | tools/phosphor-logging/templates/elog-gen-template.mako.hpp | 10 |
4 files changed, 69 insertions, 15 deletions
@@ -5,9 +5,11 @@ namespace phosphor { namespace logging { - -void commit(std::string&& e) +namespace details +{ +void commit(const char* name) { + using phosphor::logging::log; constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; @@ -46,9 +48,16 @@ void commit(std::string&& e) IFACE_INTERNAL, "Commit"); uint64_t id = sdbusplus::server::transaction::get_id(); - m.append(id, std::forward<std::string>(e)); + m.append(id, name); b.call_noreply(m); } +} // namespace details + +void commit(std::string&& name) +{ + log<level::ERR>("method is deprecated, use commit() with exception type"); + phosphor::logging::details::commit(name.c_str()); +} } // namespace logging } // namespace phosphor 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 diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp index 7ee4268..6a3ffbf 100644 --- a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp +++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp @@ -104,8 +104,8 @@ struct ${b} %> struct ${error_type} { - static constexpr auto err_code = "${name}"; - static constexpr auto err_msg = "${error_msg[name]}"; + static constexpr auto errName = "${name}"; + static constexpr auto errDesc = "${error_msg[name]}"; static constexpr auto L = level::${error_lvl[name]}; % for b in meta_list: using ${b} = _${classname}::${b}; @@ -117,17 +117,17 @@ struct ${error_type} const char* name() const noexcept { - return err_code; + return errName; } const char* description() const noexcept { - return err_msg; + return errDesc; } const char* what() const noexcept { - return err_code; + return errName; } }; |