summaryrefslogtreecommitdiffstats
path: root/phosphor-logging/log.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'phosphor-logging/log.hpp')
-rw-r--r--phosphor-logging/log.hpp81
1 files changed, 41 insertions, 40 deletions
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