Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ros/console.h"
00036 #include <log4cxx/logger.h>
00037
00038 void print(ros::console::Level level, const std::string& s)
00039 {
00040 ROS_LOG(level, ROSCONSOLE_DEFAULT_NAME, "%s", s.c_str());
00041 }
00042
00043 int main(int , char** )
00044 {
00045
00046
00047 ROSCONSOLE_AUTOINIT;
00048
00049 log4cxx::LoggerPtr my_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
00050
00051
00052 my_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Debug]);
00053
00054
00055 ROS_DEBUG("This is a debug statement, and should print");
00056 ROS_INFO("This is an info statement, and should print");
00057 ROS_WARN("This is a warn statement, and should print");
00058 ROS_ERROR("This is an error statement, and should print");
00059 ROS_FATAL("This is a fatal statement, and should print");
00060
00061
00062 print(ros::console::levels::Debug, "Hello, this should print");
00063
00064 my_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Error]);
00065
00066 print(ros::console::levels::Debug, "Hello, this will also print");
00067
00068
00069 ros::console::notifyLoggerLevelsChanged();
00070
00071 print(ros::console::levels::Debug, "Hello, this will NOT print");
00072
00073 log4cxx::LoggerPtr ros_logger = log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME);
00074
00075 my_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Debug]);
00076 ros_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Error]);
00077 ROS_DEBUG("This will still print, because the child logger's level overrides its ancestor loggers' levels");
00078
00079 log4cxx::LoggerPtr test_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME".test");
00080 test_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Error]);
00081 ROS_INFO_NAMED("test", "This will not print, because the ros.rosconsole.test logger has been set to Error verbosity");
00082 test_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Debug]);
00083 ROS_INFO_NAMED("test", "Now everything sent to the ros.rosconsole.test logger will be printed (including this)");
00084
00085 return 0;
00086 }