0
$\begingroup$

Rosanswers logo

Is there any way to change a rospy node's log level while it is running? http://www.ros.org/wiki/rospy/Overview/Logging says that you must pass in a parameter to rospy.init_node(), which means you need to kill and restart the node...

Also, I am curious why rxloggerlevel doesn't work for python nodes.


Originally posted by baxelrod on ROS Answers with karma: 794 on 2011-04-22

Post score: 7

$\endgroup$

3 Answers 3

0
$\begingroup$

Rosanswers logo

Not much hacking is required to accomplish this:

import rospy
import logging

def set_rospy_log_lvl(log_level):
    logger = logging.getLogger('rosout')
    logger.setLevel(rospy.impl.rosout._rospy_to_logging_levels[log_level])

You can use this function wherever you want (after rospy.init()) to change the log level. Works in Melodic.

Example usage:

rospy.init("my_node", anonymous=True)
set_rospy_log_lvl(rospy.DEBUG)

Originally posted by JeremyRoy with karma: 51 on 2021-12-02

This answer was ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

You currently can't do this in rospy without some severe internal API hacking. This would make a good feature request ticket (or patch).

rxloggerlevel works against an API that was developed solely for roscpp. I've been meaning to add it to rospy, but the API needs some cleanup and it's been lower priority.


Originally posted by kwc with karma: 12244 on 2011-04-22

This answer was NOT ACCEPTED on the original site

Post score: 6

$\endgroup$
0
$\begingroup$

Rosanswers logo

You can also use rosrun rqt_logger_level rqt_logger_level


Originally posted by GeorgNo with karma: 183 on 2021-12-07

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

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