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 2017-11-18 22:24:28 -0500

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.

edit retag flag offensive close merge delete

Comments

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

clyde gravatar image clyde  ( 2017-11-19 00:22:14 -0500 )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  ( 2017-11-19 04:16:56 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2017-11-19 09:33:03 -0500

lucasw gravatar image
edit flag offensive delete link more
0

answered 2017-11-20 01:39:09 -0500

R. Tellez gravatar image

updated 2017-11-20 01:39:59 -0500

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!

edit flag offensive delete link more

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  ( 2021-07-06 02:39:30 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2017-11-18 22:24:28 -0500

Seen: 3,669 times

Last updated: Nov 20 '17