Skip to content

Instantly share code, notes, and snippets.

@pgorczak
Created August 24, 2015 14:48
Show Gist options
  • Save pgorczak/5d76fc56be82c03d0789 to your computer and use it in GitHub Desktop.
Save pgorczak/5d76fc56be82c03d0789 to your computer and use it in GitHub Desktop.
Custom ROS Python logger
import logging
import rospy
# Messages sent to my_logger will not be directed to stdout.
# They will show up in rqt_console with my_logger associated to the node.
logging.getLogger('my_logger').addHandler(rospy.impl.rosout.RosOutHandler())
logging.getLogger('my_logger').setLevel(logging.INFO)
def timer_callback(event):
logger = logging.getLogger('my_logger')
logger.info('Callback at %s', str(event.current_real))
if __name__ == '__main__':
rospy.init_node('log_test', anonymous=True)
rospy.Timer(rospy.Duration(1.0), timer_callback)
rospy.spin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment