Ask Your Question
1

Retrieve loglevel of current node using rospy

asked 2018-04-24 10:16:15 -0500

igor gravatar image

Sometimes generating certain debug information may be computationally burdensome and therefore it may be desirable to make this dependent on the current log level.

Thus I was wondering, what would be the correct way to retrieve the loglevel from within a node using rospy (in Kinetic)? Ultimately, I would want to be able to do something like this:

if current_log_level == rospy.DEBUG:
  result = burdensome_stats_generation()
  rospy.logdebug("Very informative output: %s", res)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2018-04-24 11:00:33 -0500

lucasw gravatar image

updated 2018-04-24 12:55:02 -0500

This uses the python logging ( https://docs.python.org/2.4/lib/modul... ) 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())
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

2 followers

Stats

Asked: 2018-04-24 10:16:15 -0500

Seen: 130 times

Last updated: Apr 24 '18