diff --git a/benchmark/benchmark_log.cpp b/benchmark/benchmark_log.cpp index 549bbb8..e7db362 100644 --- a/benchmark/benchmark_log.cpp +++ b/benchmark/benchmark_log.cpp @@ -6,14 +6,14 @@ namespace { void BM_imp_log_no_output(benchmark::State& state) { - imp::log::gripper log {__func__, {}}; + imp::log::grip log {__func__, {}}; for (auto _ : state) { log.debug("hello log."); } } void BM_imp_log_gripper(benchmark::State& state) { - imp::log::gripper log {__func__, {}}; + imp::log::grip log {__func__, {}}; for (auto _ : state) { log.info("hello log."); } diff --git a/include/libimp/log.h b/include/libimp/log.h index 532564b..f0549a2 100644 --- a/include/libimp/log.h +++ b/include/libimp/log.h @@ -53,15 +53,11 @@ template class has_fn_output { static std::integral_constant check(...); - template - static auto check(U *u) - -> decltype(u->output(log::level::trace, std::declval()), - std::integral_constant{}); + template output(log::level::trace, std::declval()))> + static std::integral_constant check(U *u); - template - static auto check(U *u) - -> decltype(u->output(log::level::trace, std::declval()), - std::integral_constant{}); + template output(std::declval()))> + static std::integral_constant check(U *u); public: using type = decltype(check(static_cast(nullptr))); @@ -129,20 +125,25 @@ public: void output(context) noexcept; }; +/// @brief Standard console output. class LIBIMP_EXPORT std_t { public: void output(log::level, std::string &&) noexcept; }; +/// @brief Standard console output object. LIBIMP_EXPORT extern std_t std_out; -class gripper { +/** + * @brief Log information grips. + */ +class grip { printer printer_; char const *func_; level level_limit_; template - gripper &output(log::level l, Fmt &&ft, A &&... args) noexcept { + grip &output(log::level l, Fmt &&ft, A &&... args) noexcept { if (!printer_ || (enum_cast(l) < enum_cast(level_limit_))) { return *this; } @@ -163,33 +164,33 @@ class gripper { } public: - gripper(char const *func, printer printer = std_out, level level_limit = level::info) noexcept + grip(char const *func, printer printer = std_out, level level_limit = level::info) noexcept : printer_ (printer) , func_ (func) , level_limit_(level_limit) {} template - gripper &trace(Fmt &&ft, A &&... args) noexcept { + grip &trace(Fmt &&ft, A &&... args) noexcept { return output(log::level::trace, std::forward(ft), std::forward(args)...); } template - gripper &debug(Fmt &&ft, A &&... args) noexcept { + grip &debug(Fmt &&ft, A &&... args) noexcept { return output(log::level::debug, std::forward(ft), std::forward(args)...); } template - gripper &info(Fmt &&ft, A &&... args) noexcept { + grip &info(Fmt &&ft, A &&... args) noexcept { return output(log::level::info, std::forward(ft), std::forward(args)...); } template - gripper &warning(Fmt &&ft, A &&... args) noexcept { + grip &warning(Fmt &&ft, A &&... args) noexcept { return output(log::level::warning, std::forward(ft), std::forward(args)...); } template - gripper &error(Fmt &&ft, A &&... args) noexcept { + grip &error(Fmt &&ft, A &&... args) noexcept { return output(log::level::error, std::forward(ft), std::forward(args)...); } template - gripper &failed(Fmt &&ft, A &&... args) noexcept { + grip &failed(Fmt &&ft, A &&... args) noexcept { return output(log::level::failed, std::forward(ft), std::forward(args)...); } }; @@ -197,4 +198,4 @@ public: } // namespace log LIBIMP_NAMESPACE_END_ -#define LIBIMP_LOG_(...) ::LIBIMP_::log::gripper log {__func__, __VA_ARGS__} \ No newline at end of file +#define LIBIMP_LOG_(...) ::LIBIMP_::log::grip log {__func__, __VA_ARGS__} \ No newline at end of file diff --git a/src/libipc/platform/win/get_sa.h b/src/libipc/platform/win/get_sa.h index c605c2c..65c2edd 100644 --- a/src/libipc/platform/win/get_sa.h +++ b/src/libipc/platform/win/get_sa.h @@ -28,7 +28,7 @@ inline LPSECURITY_ATTRIBUTES get_sa() { initiator() { using namespace ::LIBIMP_; - log::gripper log {"get_sa"}; + log::grip log {"get_sa"}; if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) { log.error("failed: InitializeSecurityDescriptor(SECURITY_DESCRIPTOR_REVISION). error = {}", sys::error()); return; diff --git a/src/libpmr/memory_resource.cpp b/src/libpmr/memory_resource.cpp index a74dd35..98f8a82 100644 --- a/src/libpmr/memory_resource.cpp +++ b/src/libpmr/memory_resource.cpp @@ -13,7 +13,7 @@ namespace { /** * @brief Check that bytes is not 0 and that the alignment is a power of two. */ -bool verify_args(::LIBIMP_::log::gripper &log, std::size_t bytes, std::size_t alignment) noexcept { +bool verify_args(::LIBIMP_::log::grip &log, std::size_t bytes, std::size_t alignment) noexcept { if (bytes == 0) { return false; } diff --git a/test/imp/test_imp_log.cpp b/test/imp/test_imp_log.cpp index 6a005e7..c4852c0 100644 --- a/test/imp/test_imp_log.cpp +++ b/test/imp/test_imp_log.cpp @@ -74,7 +74,7 @@ TEST(log, log_printer) { TEST(log, gripper) { { - imp::log::gripper log {__func__}; + imp::log::grip log {__func__}; log.info("hello"); } {