First time here? Check out the FAQ!


ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Set log level for each node in ROS CPP

asked Nov 19 '17

ravijoshi gravatar image

I want to set the log level for each node in ROS CPP. The node is defined as follows:

ros::init(argc, argv, "my_ros_node");

What I am looking for is the CPP version of following command:

rospy.init_node('my_ros_node', log_level=rospy.DEBUG)

I am using ROS Indigo on Ubuntu 14.04 LTS. As always thank you very much.

Preview: (hide)

Comments

You can set it per package. See: http://wiki.ros.org/rosconsole#Config...

clyde gravatar image clyde  ( Nov 19 '17 )edit

@clyde: Thank you very much. I am assuming that there must be a way to do it in CPP. It is possible to do in Python, as I posted above. However I am looking for CPP version. Thanks again.

ravijoshi gravatar image ravijoshi  ( Nov 19 '17 )edit

2 Answers

Sort by » oldest newest most voted
2

answered Nov 19 '17

lucasw gravatar image
Preview: (hide)
0

answered Nov 20 '17

R. Tellez gravatar image

updated Nov 20 '17

Like @clyde and @lucasw are pointing, the solution is at the wiki page.

You basically have to use the rosconsole class of roscpp (ros.h) to change the logger level. After importing console.h you need to do the following code call:

ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug)

As you can see, the last argument indicates the level of debug you want to have for that node. After that call, you must notify, that the logger level has changed. For that, do the following:

ros::console::notifyLoggerLevelsChanged()

That is all! That simple.

Finally, have a look at this video that shows how to dynamically change the logger level for a node, showing how different messages get activated or deactivated based on the log level.

Hope it helps!

Preview: (hide)

Comments

One important thing to remember is that by default the INFO and DEBUG messages are sent to the log file instead of the terminal unless you change the output parameter to "screen" during the node launch like so:

<node name="my_node" pkg="my_pkg" type="my_node" output="screen"/>

Reference: http://wiki.ros.org/roscpp/Overview/L...

cgnarendiran gravatar image cgnarendiran  ( Jul 6 '21 )edit

Question Tools

3 followers

Stats

Asked: Nov 19 '17

Seen: 3,951 times

Last updated: Nov 20 '17