Created
August 24, 2015 14:48
-
-
Save pgorczak/5d76fc56be82c03d0789 to your computer and use it in GitHub Desktop.
Custom ROS Python logger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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