Skip to content

Commit

Permalink
MODE_NOLOG: Added support for if every n logging
Browse files Browse the repository at this point in the history
  • Loading branch information
4c3y committed Sep 7, 2023
1 parent e7c8dfa commit ec672b9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion include/log++.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(n)>); InternalLog()
#define LOG_FIRST_N(severity, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_integral_v<decltype(n)>); InternalLog()

#define DLOG_IF_EVERY_N(severity, cond, n) (void) LPP_INTL::GlogSeverity::severity; static_assert(std::is_same<decltype(cond), bool>::value && std::is_integral_v<decltype(n)>); InternalLog()
#define LOG_IF_EVERY_N(severity, cond, n) DLOG_IF_EVERY_N(severity, cond, n)

//ros
#define ROS_DEBUG_STREAM(x) (void) x
Expand Down
53 changes: 53 additions & 0 deletions test/nolog/test_nolog_if_every_n.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Created by acey on 07.09.23.
//

#include <gtest/gtest.h>
#include <log++.h>
#include <test_utils.h>

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);
}
}

0 comments on commit ec672b9

Please sign in to comment.