loggers.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_multimaster/license/LICENSE
00005 #
00006 
00007 ##############################################################################
00008 # Imports
00009 ##############################################################################
00010 
00011 from __future__ import print_function
00012 
00013 import os
00014 import sys
00015 import roslaunch.core
00016 import logging
00017 import socket
00018 import rosgraph
00019 import rospkg
00020 import rosunit
00021 from rostest.rostestutil import rostest_name_from_path
00022 
00023 
00024 ##############################################################################
00025 # Methods
00026 ##############################################################################
00027 
00028 def xml_results_file(package, results_log_name):
00029     '''
00030       Generate the absolute results log file name. This will be located in the
00031       cmake build directory, prefixed with 'rocon_test' and using the specially
00032       generated underscore separated log name.
00033     '''
00034     results_log_file = rosunit.xml_results_file(package, results_log_name, is_rostest=True)
00035     # rostest's results_file is prefixed with 'rostest' - switch it to our 'rocon_test'
00036     return results_log_file.replace('rostest', 'rocon_test', 1)
00037 
00038 def configure_logging(package, filename):
00039     '''
00040       Configures the logger and generates an underscored pkg_dir relative name
00041       (e.g. launch/pirate_chatter.multilaunch -> launch_pirate_chatter
00042     '''
00043     roslaunch.core.add_printlog_handler(logging.getLogger('rocon_test').info)
00044     roslaunch.core.add_printerrlog_handler(logging.getLogger('rocon_test').error)
00045     r = rospkg.RosPack()
00046     pkg_dir = r.get_path(package)
00047     results_log_name = rostest_name_from_path(pkg_dir, filename)
00048     log_basename = 'rocon_test-%s-%s.log' % (socket.gethostname(), os.getpid())
00049     unused_log_name = rosgraph.roslogging.configure_logging('rocon_test', filename=log_basename)
00050     results_log_file = xml_results_file(package, results_log_name)
00051     return results_log_name, results_log_file
00052 
00053 
00054 def printlog(msg, *args):
00055     if args:
00056         msg = msg % args
00057     logging.getLogger('rocon_test').info(msg)
00058     print("[ROCON_TEST] " + msg)
00059 
00060 
00061 def printlogerr(msg, *args):
00062     if args:
00063         msg = msg % args
00064     logging.getLogger('rocon_test').error(msg)
00065     print >> sys.stderr, "[ROCON_TEST] " + msg
00066 
00067 ##############################################################################
00068 # Test
00069 ##############################################################################
00070 
00071 if __name__ == '__main__':
00072     printlog(" Where is it dude?")


rocon_test
Author(s): Daniel Stonier
autogenerated on Sat Jun 8 2019 18:48:47