summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phosphor-logging/log.hpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/phosphor-logging/log.hpp b/phosphor-logging/log.hpp
index a5ba738..a933591 100644
--- a/phosphor-logging/log.hpp
+++ b/phosphor-logging/log.hpp
@@ -17,6 +17,7 @@
#pragma once
#include <tuple>
+#include <type_traits>
#include <systemd/sd-journal.h>
#include <sdbusplus/server/transaction.hpp>
@@ -135,11 +136,43 @@ void log(Msg msg, Entry... e)
details::log(log_tuple);
}
+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>
+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...>
+struct bool_pack;
+
+template<bool... bs>
+using all_true = std::is_same<bool_pack<bs..., true>, bool_pack<true, bs...>>;
+
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)...);
+ std::forward<Args>(args)...);
return entry_tuple;
}
OpenPOWER on IntegriCloud