summaryrefslogtreecommitdiffstats
path: root/phosphor-logging
diff options
context:
space:
mode:
Diffstat (limited to 'phosphor-logging')
-rw-r--r--phosphor-logging/elog.hpp110
-rw-r--r--phosphor-logging/log.hpp81
2 files changed, 88 insertions, 103 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
-
diff --git a/phosphor-logging/log.hpp b/phosphor-logging/log.hpp
index a933591..e20605b 100644
--- a/phosphor-logging/log.hpp
+++ b/phosphor-logging/log.hpp
@@ -16,10 +16,11 @@
#pragma once
-#include <tuple>
-#include <type_traits>
#include <systemd/sd-journal.h>
+
#include <sdbusplus/server/transaction.hpp>
+#include <tuple>
+#include <type_traits>
namespace phosphor
{
@@ -32,14 +33,14 @@ namespace logging
*/
enum class level
{
- EMERG = LOG_EMERG,
- ALERT = LOG_ALERT,
- CRIT = LOG_CRIT,
- ERR = LOG_ERR,
+ EMERG = LOG_EMERG,
+ ALERT = LOG_ALERT,
+ CRIT = LOG_CRIT,
+ ERR = LOG_ERR,
WARNING = LOG_WARNING,
- NOTICE = LOG_NOTICE,
- INFO = LOG_INFO,
- DEBUG = LOG_DEBUG,
+ NOTICE = LOG_NOTICE,
+ INFO = LOG_INFO,
+ DEBUG = LOG_DEBUG,
};
/** @fn log()
@@ -55,7 +56,7 @@ enum class level
* msg_str,
* entry("MY_METADATA=%s_%x, name, number));
*/
-template <level L, typename Msg, typename ...Entry>
+template <level L, typename Msg, typename... Entry>
void log(Msg msg, Entry... entry);
/** @fn entry()
@@ -68,7 +69,7 @@ void log(Msg msg, Entry... entry);
* value is of any size and format
* @param[in] args - Remaining metadata strings
*/
-template <typename Arg, typename ...Args>
+template <typename Arg, typename... Args>
constexpr auto entry(Arg&& arg, Args&&... args);
namespace details
@@ -82,7 +83,7 @@ namespace details
template <level L>
constexpr auto prio()
{
- constexpr const char *prio_str = "PRIORITY=%d";
+ constexpr const char* prio_str = "PRIORITY=%d";
constexpr const auto prio_tuple = std::make_tuple(prio_str, L);
return prio_tuple;
}
@@ -94,7 +95,7 @@ constexpr auto prio()
* @param[in] e - Tuple containing the data to be logged
* @param[unnamed] - std::integer_sequence of tuple's index values
*/
-template <typename T, size_t ...I>
+template <typename T, size_t... I>
void helper_log(T&& e, std::integer_sequence<size_t, I...>)
{
// https://www.freedesktop.org/software/systemd/man/sd_journal_print.html
@@ -116,63 +117,63 @@ void log(T&& e)
} // namespace details
-template <level L, typename Msg, typename ...Entry>
+template <level L, typename Msg, typename... Entry>
void log(Msg msg, Entry... e)
{
static_assert((std::is_same<const char*, std::decay_t<Msg>>::value ||
std::is_same<char*, std::decay_t<Msg>>::value),
"First parameter must be a C-string.");
- constexpr const char *msg_str = "MESSAGE=%s";
+ constexpr const char* msg_str = "MESSAGE=%s";
const auto msg_tuple = std::make_tuple(msg_str, std::forward<Msg>(msg));
constexpr auto transactionStr = "TRANSACTION_ID=%lld";
auto transactionId = sdbusplus::server::transaction::get_id();
- auto log_tuple = std::tuple_cat(details::prio<L>(),
- msg_tuple,
+ auto log_tuple = std::tuple_cat(details::prio<L>(), msg_tuple,
entry(transactionStr, transactionId),
std::forward<Entry>(e)...);
details::log(log_tuple);
}
-template<class T>
+template <class T>
struct is_printf_argtype
: std::integral_constant<
- bool,
- (std::is_integral<typename std::remove_reference<T>::type>::value ||
- std::is_enum<typename std::remove_reference<T>::type>::value ||
- std::is_floating_point<typename
- std::remove_reference<T>::type>::value ||
- std::is_pointer<typename std::decay<T>::type>::value)>
-{};
-
-template<class T>
+ bool,
+ (std::is_integral<typename std::remove_reference<T>::type>::value ||
+ std::is_enum<typename std::remove_reference<T>::type>::value ||
+ std::is_floating_point<
+ typename std::remove_reference<T>::type>::value ||
+ std::is_pointer<typename std::decay<T>::type>::value)>
+{
+};
+
+template <class T>
struct is_char_ptr_argtype
: std::integral_constant<
- bool,
- (std::is_pointer<typename std::decay<T>::type>::value &&
- std::is_same<typename std::remove_cv<typename
- std::remove_pointer<typename
- std::decay<T>::type>::type>::type,
- char>::value)>
-{};
-
-template<bool...>
+ bool,
+ (std::is_pointer<typename std::decay<T>::type>::value &&
+ std::is_same<typename std::remove_cv<typename std::remove_pointer<
+ typename std::decay<T>::type>::type>::type,
+ char>::value)>
+{
+};
+
+template <bool...>
struct bool_pack;
-template<bool... bs>
+template <bool... bs>
using all_true = std::is_same<bool_pack<bs..., true>, bool_pack<true, bs...>>;
-template <typename Arg, typename ...Args>
+template <typename Arg, typename... Args>
constexpr auto entry(Arg&& arg, Args&&... args)
{
static_assert(is_char_ptr_argtype<Arg>::value,
"bad argument type: use char*");
static_assert(all_true<is_printf_argtype<Args>::value...>::value,
"bad argument type: use string.c_str() if needed");
- const auto entry_tuple = std::make_tuple(std::forward<Arg>(arg),
- std::forward<Args>(args)...);
+ const auto entry_tuple =
+ std::make_tuple(std::forward<Arg>(arg), std::forward<Args>(args)...);
return entry_tuple;
}
OpenPOWER on IntegriCloud