From ec672b90af3d08df99b23e0c5afb4ea45f1eddf9 Mon Sep 17 00:00:00 2001 From: 4c3y <69460051+4c3y@users.noreply.github.com> Date: Thu, 7 Sep 2023 15:59:03 +0200 Subject: [PATCH] MODE_NOLOG: Added support for if every n logging --- CMakeLists.txt | 2 +- include/log++.h | 3 +- test/nolog/test_nolog_if_every_n.cc | 53 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/nolog/test_nolog_if_every_n.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 90f1215..43cccc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,7 +162,7 @@ if (GLOG_FOUND AND catkin_FOUND AND LPP_BUILD_TESTS) test/nolog/test_nolog_basic.cc test/nolog/test_nolog_every_n.cc test/nolog/test_nolog_first_n.cc - #test/nolog/test_nolog_if_every_n.cc + test/nolog/test_nolog_if_every_n.cc #test/nolog/test_nolog_log_string.cc #test/nolog/test_nolog_rosprintf.cc #test/nolog/test_nolog_timed.cc diff --git a/include/log++.h b/include/log++.h index e27bbe7..a25a670 100644 --- a/include/log++.h +++ b/include/log++.h @@ -444,7 +444,8 @@ LPP_INTL::InternalPolicyLog(LPP_GET_KEY(), n, LPP_INTL::BaseSeverity::DEBUG, LPP #define LOG_EVERY_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; InternalLog() #define DLOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral_v); InternalLog() #define LOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral_v); InternalLog() - +#define DLOG_IF_EVERY_N(severity, cond, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same::value && std::is_integral_v); InternalLog() +#define LOG_IF_EVERY_N(severity, cond, n) DLOG_IF_EVERY_N(severity, cond, n) //ros #define ROS_DEBUG_STREAM(x) (void) x diff --git a/test/nolog/test_nolog_if_every_n.cc b/test/nolog/test_nolog_if_every_n.cc new file mode 100644 index 0000000..e39c21e --- /dev/null +++ b/test/nolog/test_nolog_if_every_n.cc @@ -0,0 +1,53 @@ +// +// Created by acey on 07.09.23. +// + +#include +#include +#include + +TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_debug) { + LOG_INIT(*test_argv); + + for (int i = 0; i < 5; i++) { + std::string output = LPP_CAPTURE_STDOUT(DLOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 12); + ASSERT_EQ("", output); + } +} + +TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_info) { + LOG_INIT(*test_argv); + + for (int i = 0; i < 5; i++) { + std::string output = LPP_CAPTURE_STDOUT(LOG_IF_EVERY_N(INFO, i <= 3, 3) << "Test" << 12); + ASSERT_EQ("", output); + } +} + +TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_warning) { + LOG_INIT(*test_argv); + + for (int i = 0; i < 5; i++) { + std::string output = LPP_CAPTURE_STDERR(LOG_IF_EVERY_N(WARNING, i <= 3, 3) << "Test" << 12); + ASSERT_EQ("", output); + } +} + +TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_error) { + LOG_INIT(*test_argv); + + for (int i = 0; i < 5; i++) { + std::string output = LPP_CAPTURE_STDERR(LOG_IF_EVERY_N(ERROR, i <= 3, 3) << "Test" << 12); + ASSERT_EQ("", output); + } +} + +TEST(nolog_if_every_n, glog_syntax_if_every_n_severity_fatal) { + LOG_INIT(*test_argv); + + for (int i = 0; i < 5; i++) { + std::string output = LPP_CAPTURE_STDERR(LOG_IF_EVERY_N(FATAL, i <= 3, 3) << "Test" << 12); + ASSERT_EQ("", output); + } +} +