0
$\begingroup$

Rosanswers logo

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)


Originally posted by tor on ROS Answers with karma: 277 on 2012-09-07

Post score: 5


Original comments

Comment by Rufus on 2020-05-17:
Related: https://answers.ros.org/question/197964/set-log-level-in-launch-file/?answer=350817#post-id-350817

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

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>

Originally posted by hvpandya with karma: 76 on 2015-11-20

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

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)

Originally posted by jarvisschultz with karma: 9031 on 2012-09-08

This answer was NOT ACCEPTED on the original site

Post score: 2


Original comments

Comment by Lorenz on 2012-09-10:
For completeness: in roslisp you have the method set-debug-level to set the level of a specific logger.

Comment by Dirk Thomas on 2014-01-14:
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).

$\endgroup$
0
$\begingroup$

Rosanswers logo

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
  1. 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.


Originally posted by Avio with karma: 96 on 2015-11-20

This answer was NOT ACCEPTED on the original site

Post score: 4

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.