This uses the python logging (https://docs.python.org/2.4/lib/module-logging.html) underneath rospy logging:
#!/usr/bin/env python
import rospy
import logging
rospy.init_node('log_test')
logger = logging.getLogger("rosout")
logger.setLevel(logging.INFO)
level = logger.getEffectiveLevel()
rospy.loginfo("info test, level = " + str(level))
rospy.logdebug("debug test, level = level " + str(level))
logger.setLevel(logging.DEBUG)
level = logger.getEffectiveLevel()
rospy.loginfo("info test, level = " + str(level))
rospy.logdebug("debug test, level = level " + str(level))
Old suggestions, maybe I'll test them out:
rospy service call to get_loggers service. (Maybe some extra things to do to properly call service from same node that is providing it)
I don't think there is anything in python like a C macro that could avoid evaluating a function parameter if debug wasn't on (does the actual C++ debug do anything like that?), it would be nice if this could be done:
rospy.logdebug("Very informative output: %s", burdensome_stats_generation())
Originally posted by lucasw with karma: 8729 on 2018-04-24
This answer was ACCEPTED on the original site
Post score: 2