32 #include "log4cxx/appenderskeleton.h" 33 #include "log4cxx/spi/loggingevent.h" 36 #include "log4cxx/helpers/transcoder.h" 42 #include <gtest/gtest.h> 44 #include <boost/shared_array.hpp> 61 virtual void append(
const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool&)
64 info.level_ =
event->getLevel();
66 LOG4CXX_ENCODE_CHAR(msgstr, event->getMessage());
67 info.message_ = msgstr;
69 LOG4CXX_ENCODE_CHAR(loggerstr, event->getLoggerName());
70 info.logger_name_ = loggerstr;
72 info.message_ =
event->getMessage();
73 info.logger_name_ =
event->getLoggerName();
76 info_.push_back( info );
91 virtual void append(
const log4cxx::spi::LoggingEventPtr&, log4cxx::helpers::Pool&)
93 throw std::runtime_error(
"This should be caught");
118 #define DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \ 119 TEST(RosConsole, name##Cond) \ 121 TestAppender* appender = new TestAppender; \ 122 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 123 macro_base##_COND(true, "Testing %d %d %d", 1, 2, 3); \ 124 macro_base##_COND(false, "Testing %d %d %d", 1, 2, 3); \ 125 ASSERT_EQ((int)appender->info_.size(), 1); \ 126 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 127 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 128 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 130 TEST(RosConsole, name##NamedCond) \ 132 TestAppender* appender = new TestAppender; \ 133 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 134 macro_base##_COND_NAMED(true, "test", "Testing %d %d %d", 1, 2, 3); \ 135 macro_base##_COND_NAMED(false, "test", "Testing %d %d %d", 1, 2, 3); \ 136 ASSERT_EQ((int)appender->info_.size(), 1); \ 137 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 138 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 139 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 140 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 142 TEST(RosConsole, name##StreamCond) \ 144 TestAppender* appender = new TestAppender; \ 145 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 146 macro_base##_STREAM_COND(true, "Testing " << 1 << " " << 2 << " " << 3); \ 147 macro_base##_STREAM_COND(false, "Testing " << 1 << " " << 2 << " " << 3); \ 148 ASSERT_EQ((int)appender->info_.size(), 1); \ 149 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 150 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 151 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 153 TEST(RosConsole, name##StreamCondNamed) \ 155 TestAppender* appender = new TestAppender; \ 156 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 157 macro_base##_STREAM_COND_NAMED(true, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 158 macro_base##_STREAM_COND_NAMED(false, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 159 ASSERT_EQ((int)appender->info_.size(), 1); \ 160 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 161 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 162 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 163 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 166 #define DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \ 167 TEST(RosConsole, name##Once) \ 169 TestAppender* appender = new TestAppender; \ 170 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 171 macro_base##_ONCE("Testing %d %d %d", 1, 2, 3); \ 172 ASSERT_EQ((int)appender->info_.size(), 1); \ 173 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 174 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 175 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 177 TEST(RosConsole, name##NamedOnce) \ 179 TestAppender* appender = new TestAppender; \ 180 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 181 macro_base##_ONCE_NAMED("test", "Testing %d %d %d", 1, 2, 3); \ 182 ASSERT_EQ((int)appender->info_.size(), 1); \ 183 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 184 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 185 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 186 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 188 TEST(RosConsole, name##StreamOnce) \ 190 TestAppender* appender = new TestAppender; \ 191 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 192 macro_base##_STREAM_ONCE("Testing " << 1 << " " << 2 << " " << 3); \ 193 ASSERT_EQ((int)appender->info_.size(), 1); \ 194 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 195 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 196 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 198 TEST(RosConsole, name##StreamOnceNamed) \ 200 TestAppender* appender = new TestAppender; \ 201 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 202 macro_base##_STREAM_ONCE_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \ 203 ASSERT_EQ((int)appender->info_.size(), 1); \ 204 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 205 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 206 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 207 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 210 #define DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \ 211 TEST(RosConsole, name##Throttle) \ 213 TestAppender* appender = new TestAppender; \ 214 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 215 macro_base##_THROTTLE(0.5, "Testing %d %d %d", 1, 2, 3); \ 216 ASSERT_EQ((int)appender->info_.size(), 1); \ 217 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 218 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 219 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 221 TEST(RosConsole, name##NamedThrottle) \ 223 TestAppender* appender = new TestAppender; \ 224 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 225 macro_base##_THROTTLE_NAMED(0.5, "test", "Testing %d %d %d", 1, 2, 3); \ 226 ASSERT_EQ((int)appender->info_.size(), 1); \ 227 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 228 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 229 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 230 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 232 TEST(RosConsole, name##StreamThrottle) \ 234 TestAppender* appender = new TestAppender; \ 235 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 236 macro_base##_STREAM_THROTTLE(0.5, "Testing " << 1 << " " << 2 << " " << 3); \ 237 ASSERT_EQ((int)appender->info_.size(), 1); \ 238 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 239 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 240 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 242 TEST(RosConsole, name##StreamThrottleNamed) \ 244 TestAppender* appender = new TestAppender; \ 245 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 246 macro_base##_STREAM_THROTTLE_NAMED(0.5, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 247 ASSERT_EQ((int)appender->info_.size(), 1); \ 248 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 249 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 250 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 251 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 254 #define DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level) \ 255 TEST(RosConsole, name##Filter) \ 257 TestAppender* appender = new TestAppender; \ 258 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 259 macro_base##_FILTER(&g_filter, "Testing %d %d %d", 1, 2, 3); \ 260 ASSERT_EQ((int)appender->info_.size(), 1); \ 261 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 262 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 263 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 265 TEST(RosConsole, name##NamedFilter) \ 267 TestAppender* appender = new TestAppender; \ 268 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 269 macro_base##_FILTER_NAMED(&g_filter, "test", "Testing %d %d %d", 1, 2, 3); \ 270 ASSERT_EQ((int)appender->info_.size(), 1); \ 271 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 272 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 273 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 274 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 276 TEST(RosConsole, name##StreamFilter) \ 278 TestAppender* appender = new TestAppender; \ 279 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 280 macro_base##_STREAM_FILTER(&g_filter, "Testing " << 1 << " " << 2 << " " << 3); \ 281 ASSERT_EQ((int)appender->info_.size(), 1); \ 282 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 283 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 284 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 286 TEST(RosConsole, name##StreamFilterNamed) \ 288 TestAppender* appender = new TestAppender; \ 289 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 290 macro_base##_STREAM_FILTER_NAMED(&g_filter, "test", "Testing " << 1 << " " << 2 << " " << 3); \ 291 ASSERT_EQ((int)appender->info_.size(), 1); \ 292 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 293 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 294 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 295 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 298 #define DEFINE_LEVEL_TESTS(name, macro_base, level, log4cxx_level) \ 299 TEST(RosConsole, name) \ 301 TestAppender* appender = new TestAppender; \ 302 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 303 macro_base("Testing %d %d %d", 1, 2, 3); \ 304 ASSERT_EQ((int)appender->info_.size(), 1); \ 305 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 306 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 307 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 309 TEST(RosConsole, name##Named) \ 311 TestAppender* appender = new TestAppender; \ 312 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 313 macro_base##_NAMED("test", "Testing %d %d %d", 1, 2, 3); \ 314 ASSERT_EQ((int)appender->info_.size(), 1); \ 315 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 316 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 317 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 318 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 320 TEST(RosConsole, name##Stream) \ 322 TestAppender* appender = new TestAppender; \ 323 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 324 macro_base##_STREAM("Testing " << 1 << " " << 2 << " " << 3); \ 325 ASSERT_EQ((int)appender->info_.size(), 1); \ 326 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 327 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 328 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 330 TEST(RosConsole, name##StreamNamed) \ 332 TestAppender* appender = new TestAppender; \ 333 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->addAppender( appender ); \ 334 macro_base##_STREAM_NAMED("test", "Testing " << 1 << " " << 2 << " " << 3); \ 335 ASSERT_EQ((int)appender->info_.size(), 1); \ 336 EXPECT_STREQ(appender->info_[0].message_.c_str(), "Testing 1 2 3"); \ 337 EXPECT_EQ(appender->info_[0].level_, log4cxx_level); \ 338 EXPECT_STREQ(appender->info_[0].logger_name_.c_str(), ROSCONSOLE_ROOT_LOGGER_NAME".rosconsole.test"); \ 339 log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME)->removeAppender( appender ); \ 341 DEFINE_COND_TESTS(name, macro_base, level, log4cxx_level) \ 342 DEFINE_ONCE_TESTS(name, macro_base, level, log4cxx_level) \ 343 DEFINE_THROTTLE_TESTS(name, macro_base, level, log4cxx_level) \ 344 DEFINE_FILTER_TESTS(name, macro_base, level, log4cxx_level) 352 TEST(RosConsole, loggingLevels)
357 logger->addAppender( appender );
363 logger->setLevel( log4cxx::Level::getInfo() );
364 pre_count = appender->
info_.size();
370 post_count = appender->
info_.size();
371 EXPECT_EQ(post_count, pre_count + 4);
373 logger->setLevel( log4cxx::Level::getWarn() );
374 pre_count = appender->
info_.size();
380 post_count = appender->
info_.size();
381 EXPECT_EQ(post_count, pre_count + 3);
383 logger->setLevel( log4cxx::Level::getError() );
384 pre_count = appender->
info_.size();
390 post_count = appender->
info_.size();
391 EXPECT_EQ(post_count, pre_count + 2);
393 logger->setLevel( log4cxx::Level::getFatal() );
394 pre_count = appender->
info_.size();
400 post_count = appender->
info_.size();
401 EXPECT_EQ(post_count, pre_count + 1);
403 logger->setLevel( log4cxx::Level::getOff() );
404 pre_count = appender->
info_.size();
410 post_count = appender->
info_.size();
411 EXPECT_EQ(post_count, pre_count);
415 logger->setLevel( log4cxx::Level::getInfo() );
416 pre_count = appender->
info_.size();
422 post_count = appender->
info_.size();
423 EXPECT_EQ(post_count, pre_count + 4);
425 logger->setLevel( log4cxx::Level::getWarn() );
426 pre_count = appender->
info_.size();
432 post_count = appender->
info_.size();
433 EXPECT_EQ(post_count, pre_count + 3);
435 logger->setLevel( log4cxx::Level::getError() );
436 pre_count = appender->
info_.size();
442 post_count = appender->
info_.size();
443 EXPECT_EQ(post_count, pre_count + 2);
445 logger->setLevel( log4cxx::Level::getFatal() );
446 pre_count = appender->
info_.size();
452 post_count = appender->
info_.size();
453 EXPECT_EQ(post_count, pre_count + 1);
455 logger->setLevel( log4cxx::Level::getOff() );
456 pre_count = appender->
info_.size();
462 post_count = appender->
info_.size();
463 EXPECT_EQ(post_count, pre_count);
467 logger->setLevel( log4cxx::Level::getInfo() );
468 pre_count = appender->
info_.size();
474 post_count = appender->
info_.size();
475 EXPECT_EQ(post_count, pre_count + 4);
477 logger->setLevel( log4cxx::Level::getWarn() );
478 pre_count = appender->
info_.size();
484 post_count = appender->
info_.size();
485 EXPECT_EQ(post_count, pre_count + 3);
487 logger->setLevel( log4cxx::Level::getError() );
488 pre_count = appender->
info_.size();
494 post_count = appender->
info_.size();
495 EXPECT_EQ(post_count, pre_count + 2);
497 logger->setLevel( log4cxx::Level::getFatal() );
498 pre_count = appender->
info_.size();
504 post_count = appender->
info_.size();
505 EXPECT_EQ(post_count, pre_count + 1);
507 logger->setLevel( log4cxx::Level::getOff() );
508 pre_count = appender->
info_.size();
514 post_count = appender->
info_.size();
515 EXPECT_EQ(post_count, pre_count);
519 logger->setLevel( log4cxx::Level::getInfo() );
520 pre_count = appender->
info_.size();
526 post_count = appender->
info_.size();
527 EXPECT_EQ(post_count, pre_count + 4);
529 logger->setLevel( log4cxx::Level::getWarn() );
530 pre_count = appender->
info_.size();
536 post_count = appender->
info_.size();
537 EXPECT_EQ(post_count, pre_count + 3);
539 logger->setLevel( log4cxx::Level::getError() );
540 pre_count = appender->
info_.size();
546 post_count = appender->
info_.size();
547 EXPECT_EQ(post_count, pre_count + 2);
549 logger->setLevel( log4cxx::Level::getFatal() );
550 pre_count = appender->
info_.size();
556 post_count = appender->
info_.size();
557 EXPECT_EQ(post_count, pre_count + 1);
559 logger->setLevel( log4cxx::Level::getOff() );
560 pre_count = appender->
info_.size();
566 post_count = appender->
info_.size();
567 EXPECT_EQ(post_count, pre_count);
570 logger->removeAppender( appender );
573 TEST(RosConsole, changingLevel)
578 logger->addAppender( appender );
580 logger->setLevel( log4cxx::Level::getError() );
586 EXPECT_EQ((
int)appender->
info_.size(), 2);
588 logger->removeAppender( appender );
590 logger->setLevel( log4cxx::Level::getDebug() );
593 TEST(RosConsole, changingLoggerLevel)
598 logger->addAppender( appender );
600 logger->setLevel(log4cxx::Level::getDebug());
604 logger->setLevel(log4cxx::Level::getInfo());
608 logger->setLevel(log4cxx::Level::getWarn());
612 logger->setLevel(log4cxx::Level::getError());
616 logger->setLevel(log4cxx::Level::getFatal());
620 EXPECT_EQ((
int)appender->
info_.size(), 5);
622 logger->removeAppender( appender );
624 logger->setLevel( log4cxx::Level::getDebug() );
627 TEST(RosConsole, longPrintfStyleOutput)
632 logger->addAppender( appender );
634 std::stringstream ss;
635 for (
int i = 0; i < 100000; ++i )
642 ASSERT_EQ((
int)appender->
info_.size(), 1);
643 EXPECT_STREQ(appender->
info_[0].message_.c_str(), ss.str().c_str());
645 logger->removeAppender( appender );
647 logger->setLevel( log4cxx::Level::getDebug() );
650 TEST(RosConsole, throwingAppender)
655 logger->addAppender( appender );
661 catch (std::exception& e)
666 logger->removeAppender( appender );
667 logger->setLevel( log4cxx::Level::getDebug() );
680 logger->addAppender(appender);
685 EXPECT_EQ(appender->
info_.size(), 1ULL);
687 logger->removeAppender(appender);
700 logger->addAppender(appender);
711 EXPECT_EQ(appender->
info_.size(), 2ULL);
713 logger->removeAppender(appender);
726 TEST(RosConsole, delayedThrottle)
731 logger->addAppender(appender);
740 EXPECT_EQ(appender->
info_.size(), 0ULL);
742 const int pre_count = appender->
info_.size();
750 const int post_count = appender->
info_.size();
752 EXPECT_EQ(post_count, pre_count + 1);
754 logger->removeAppender(appender);
768 logger->addAppender(appender);
773 EXPECT_EQ(appender->
info_.size(), 1ULL);
775 logger->removeAppender(appender);
783 TEST(RosConsole, throttleStream)
788 logger->addAppender(appender);
799 EXPECT_EQ(appender->
info_.size(), 2ULL);
801 logger->removeAppender(appender);
814 TEST(RosConsole, delayedStreamThrottle)
819 logger->addAppender(appender);
828 EXPECT_EQ(appender->
info_.size(), 0ULL);
830 const int pre_count = appender->
info_.size();
838 const int post_count = appender->
info_.size();
840 EXPECT_EQ(post_count, pre_count + 1);
842 logger->removeAppender(appender);
850 logger->addAppender(appender);
856 ASSERT_EQ(appender->
info_.size(), 1ULL);
857 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
859 logger->removeAppender(appender);
862 TEST(RosConsole, basicFilterStream)
867 logger->addAppender(appender);
873 ASSERT_EQ(appender->
info_.size(), 1ULL);
874 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
876 logger->removeAppender(appender);
898 TEST(RosConsole, advancedFilter)
903 logger->addAppender(appender);
909 ASSERT_EQ(appender->
info_.size(), 1ULL);
910 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
911 EXPECT_EQ(trueFilter.count_, 1);
912 EXPECT_EQ(falseFilter.
count_, 1);
914 logger->removeAppender(appender);
917 TEST(RosConsole, advancedFilterStream)
922 logger->addAppender(appender);
928 ASSERT_EQ(appender->
info_.size(), 1ULL);
929 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"Hello");
930 EXPECT_EQ(trueFilter.count_, 1);
931 EXPECT_EQ(falseFilter.
count_, 1);
933 logger->removeAppender(appender);
952 logger->addAppender(appender);
957 ASSERT_EQ(appender->
info_.size(), 1ULL);
958 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"haha");
959 EXPECT_EQ(appender->
info_[0].level_, log4cxx::Level::getError());
961 logger->removeAppender(appender);
964 TEST(RosConsole, changeFilterStream)
969 logger->addAppender(appender);
974 ASSERT_EQ(appender->
info_.size(), 1ULL);
975 EXPECT_STREQ(appender->
info_[0].message_.c_str(),
"haha");
976 EXPECT_EQ(appender->
info_[0].level_, log4cxx::Level::getError());
978 logger->removeAppender(appender);
981 TEST(RosConsole, formatToBufferInitialZero)
986 EXPECT_EQ(size, 14U);
987 EXPECT_STREQ(buffer.get(),
"Hello World 5");
990 TEST(RosConsole, formatToBufferInitialLargerThanFormat)
995 EXPECT_EQ(size, 30U);
996 EXPECT_STREQ(buffer.get(),
"Hello World 5");
1002 EXPECT_STREQ(str.c_str(),
"Hello World 5");
1007 testing::InitGoogleTest(&argc, argv);
1012 log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getDebug());
1015 return RUN_ALL_TESTS();
virtual bool requiresLayout() const
#define ROS_LOG_THROTTLE(period, level, name,...)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing...
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
#define ROS_INFO_NAMED(name,...)
AdvancedFilter(bool enabled)
#define ROS_DEBUG_STREAM_NAMED(name, args)
ROSCONSOLE_DECL void notifyLoggerLevelsChanged()
Tells the system that a logger's level has changed.
Base-class for filters. Filters allow full user-defined control over whether or not a message should ...
#define DEFINE_LEVEL_TESTS(name, macro_base, level, log4cxx_level)
#define ROS_ERROR_STREAM_NAMED(name, args)
Parameter structure passed to FilterBase::isEnabled(...);. Includes both input and output parameters...
#define ROS_WARN_NAMED(name,...)
#define ROS_LOG_STREAM_THROTTLE(period, level, name, args)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing...
const char * message
[input] The formatted message that will be output
#define ROS_INFO_STREAM_NAMED(name, args)
#define ROSCONSOLE_AUTOINIT
Initializes the rosconsole library. Usually unnecessary to call directly.
virtual void append(const log4cxx::spi::LoggingEventPtr &, log4cxx::helpers::Pool &)
ROSCONSOLE_DECL std::string formatToString(const char *fmt,...)
#define ROSCONSOLE_ROOT_LOGGER_NAME
std::string out_message
[output] If set, writes this message instead of the original
Level level
[input/output] Severity level. If changed, uses the new level
BasicFilter(bool enabled)
#define ROS_LOG_STREAM_ONCE(level, name, args)
Log to a given named logger at a given verbosity level, only the first time it is hit when enabled...
#define ROS_DEBUG_NAMED(name,...)
#define ROS_FATAL_STREAM(args)
#define ROS_FATAL_STREAM_NAMED(name, args)
void delayedThrottleStreamFunc2()
const char * file
[input] File the message came from
std::vector< Info > V_Info
int main(int argc, char **argv)
const char * function
[input] Function the message came from
void delayedThrottleFunc2()
#define ROS_LOG_DELAYED_THROTTLE(period, level, name,...)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing...
void throttleStreamFunc()
#define ROS_WARN_STREAM(args)
BasicFilter g_filter(true)
#define ROS_DEBUG_STREAM(args)
void delayedThrottleFunc()
virtual void append(const log4cxx::spi::LoggingEventPtr &event, log4cxx::helpers::Pool &)
virtual bool isEnabled(ros::console::FilterParams ¶ms)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
virtual bool isEnabled()
Returns whether or not the log statement should be printed. Called before the log arguments are evalu...
#define ROS_LOG(level, name,...)
Log to a given named logger at a given verbosity level, with printf-style formatting.
#define ROS_INFO_STREAM(args)
void delayedThrottleStreamFunc()
#define ROS_LOG_FILTER(filter, level, name,...)
Log to a given named logger at a given verbosity level, with user-defined filtering, with printf-style formatting.
#define ROS_FATAL_NAMED(name,...)
int line
[input] Line the message came from
#define ROS_ERROR_NAMED(name,...)
#define ROS_LOG_STREAM_FILTER(filter, level, name, args)
Log to a given named logger at a given verbosity level, with user-defined filtering, with stream-style formatting.
#define ROS_LOG_STREAM_DELAYED_THROTTLE(period, level, name, args)
Log to a given named logger at a given verbosity level, limited to a specific rate of printing and po...
#define ROS_LOG_ONCE(level, name,...)
Log to a given named logger at a given verbosity level, only the first time it is hit when enabled...
#define ROS_ERROR_STREAM(args)
virtual bool requiresLayout() const
TEST(RosConsole, loggingLevels)
virtual bool isEnabled(ros::console::FilterParams ¶ms)
Returns whether or not the log statement should be printed. Called once the message has been formatte...
#define ROSCONSOLE_DEFAULT_NAME
ROSCONSOLE_DECL void formatToBuffer(boost::shared_array< char > &buffer, size_t &buffer_size, const char *fmt,...)
#define ROS_WARN_STREAM_NAMED(name, args)