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

How to set verbosity/logger levels programmatically?

asked 2012-09-07 17:06:35 -0600

tor gravatar image

updated 2012-09-07 17:07:06 -0600

Hi All,

Is there a way to set verbosity/logger levels programmatically (up to node levels if possible)? How?

I have looked at here and here. It seems that I should somehow use log4cxx::Logger, cmiiw, but still do not know exactly how? Please help.

Thanks a lot. PS: Hopefully, for both roscpp and rospy (+roslisp)

edit retag flag offensive close merge delete

Comments

Rufus gravatar image Rufus  ( 2020-05-17 23:39:20 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
2

answered 2015-11-20 13:32:16 -0600

hvpandya gravatar image

Or simply add

 if( ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME, ros::console::levels::Debug) )
    ros::console::notifyLoggerLevelsChanged();

in your nodes constructor. Replace Debug with your required logger level.

Don't forget to

#include <ros/console.h>
edit flag offensive delete link more
4

answered 2015-11-20 09:50:18 -0600

Avio gravatar image

updated 2015-11-20 09:53:48 -0600

For anybody stumbling upon this page, if you just want to set verbosity of packages as soon as they are launched by launchfiles, the easiest way is:

  1. to export ROSCONSOLE_CONFIG_FILE="/path/to/my/config/rosconsole.config"
  2. edit, for example with vi /path/to/my/config/rosconsole.config adding these lines:

log4j.logger.ros=INFO

log4j.logger.ros.roscpp.superdebug=WARN

log4j.logger.ros.my_package_name=DEBUG

3. launch your launchfile in the same shell.

The package name must be the one who corresponds to <node pkg="my_package_name" ...> line in the launchfile.

edit flag offensive delete link more
2

answered 2012-09-08 10:28:56 -0600

updated 2017-02-22 17:42:28 -0600

I do this quite often when writing new nodes in C++. Usually what I do is place the following little snippet right after my call to ros::init

log4cxx::LoggerPtr my_logger =
           log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
my_logger->setLevel(
           ros::console::g_level_lookup[ros::console::levels::Debug]);

This will set the node's log level to Debug. Then I comment it out after the node is sufficiently developed. I have never really looked into doing this in rospy or roslisp, but would also be interested in figuring out how.

EDIT

I just realized that this is quite easy to do with rospy as well. As documented here, you can simply pass the log_level argument to a call to rospy.init_node() e.g.

rospy.init_node('my_node', log_level=rospy.DEBUG)
edit flag offensive delete link more

Comments

For completeness: in roslisp you have the method set-debug-level to set the level of a specific logger.

Lorenz gravatar image Lorenz  ( 2012-09-10 05:43:05 -0600 )edit
1

You should not use `g_level_lookup` to map the ROS debug level to the log4cxx log level. Instead use the log4cxx level directly. Besides the package must specify a dependency on log4cxx in its package manifest and the cpp file must include the necessary log4cxx header(s).

Dirk Thomas gravatar image Dirk Thomas  ( 2014-01-14 13:45:51 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2012-09-07 17:06:35 -0600

Seen: 6,624 times

Last updated: Feb 22 '17