Ask Your Question

Set log level for each node in ROS CPP

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

Ravi Joshi 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


You can set it per package. See:

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.

Ravi Joshi gravatar image Ravi Joshi  ( 2017-11-19 04:16:56 -0500 )edit

2 Answers

Sort by » oldest newest most voted

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

lucasw gravatar image
edit flag offensive delete link more

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:


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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 2,148 times

Last updated: Nov 20 '17