1. Log Level
Similar log message Log into five different definitions of severity macros, and the severity of Android, the following basic macro:
ROS_DEBUG_STREAM, ROS_INFO_STREAM, ROS_WARN_STREAM, ROS_ERROR_STREAM, ROS_FATAL_STREAM (in accordance with the sort of serious procedural level, low to high)
C++代码: #include <ros/ros.h> int main(int argc, char** argv){ ros::init(argc, argv, "hello_ros"); ros::NodeHandle nh; ROS_DEBUG_STREAM("Log DEBUG"); ROS_INFO_STREAM("Log INFO"); ROS_WARN_STREAM("Log WARN"); ROS_ERROR_STREAM("Log ERROR"); ROS_FATAL_STREAM("Log FATAL"); }
From the running results, you will find that DEBUG not print, Why? Calm, will answer 4
2. cycle single log
Add _ONCE behind macro basis, on behalf of the log only the first will be printed in the journal loop iteration:
C++代码: #include <ros/ros.h> int main(int argc, char** argv){ ros::init(argc, argv, "hello_ros"); ros::NodeHandle nh; for(int i = 0; i < 10; i++){ ROS_INFO_STREAM_ONCE("Log info i = " << i); if(i >= 2){ ROS_INFO_STREAM_ONCE("Log info i = " << i); } } }
3. Frequency Log
Add back _THROTTLE macro base frequency becomes log into ROS_INFO_STREAM_THROTTLE (interval, message), a first parameter representative of interval in seconds the amount of time per unit time indicates the minimum time interval between occurrences of two log
4. Open, Close log
1 mentioned in DEBUG log information is not output, because the C ++ program the default log level is INFO, DEBUG logs all been ignored, and that question is, how to open the DEBUG level log it?
rosservice call /node-name/set_logger_level ros.package-name level
C++代码: #include <ros/ros.h> int main(int argc, char** argv){ ros::init(argc, argv, "hello_ros"); ros::NodeHandle nh; while(ros::ok()){ ROS_DEBUG_STREAM("Log DEBUG"); ROS_INFO_STREAM("Log INFO"); ROS_WARN_STREAM("Log WARN"); ROS_ERROR_STREAM("ERROR log " ); ROS_FATAL_STREAM ( " log FATAL " ); } } boot upper node, and then run the terminal Call rosservice / hello_ros / set_logger_level ros.hello the DEBUG
Transfer: https: //www.jianshu.com/p/b360728ad6d1