Package rocon_test :: Module loggers
[frames] | no frames]

Source Code for Module rocon_test.loggers

 1  #!/usr/bin/env python 
 2  # 
 3  # License: BSD 
 4  #   https://raw.github.com/robotics-in-concert/rocon_multimaster/hydro-devel/rocon_test/LICENSE 
 5  # 
 6   
 7  ############################################################################## 
 8  # Imports 
 9  ############################################################################## 
10   
11  from __future__ import print_function 
12   
13  import os 
14  import sys 
15  import roslaunch.core 
16  import logging 
17  import socket 
18  import rosgraph 
19  import rospkg 
20  import rosunit 
21  from rostest.rostestutil import rostest_name_from_path 
22   
23   
24  ############################################################################## 
25  # Methods 
26  ############################################################################## 
27   
28   
29 -def configure_logging(package, filename):
30 ''' 31 Configures the logger and generates an underscored pkg_dir relative name 32 (e.g. launch/pirate_chatter.multilaunch -> launch_pirate_chatter 33 ''' 34 roslaunch.core.add_printlog_handler(logging.getLogger('rocon_test').info) 35 roslaunch.core.add_printerrlog_handler(logging.getLogger('rocon_test').error) 36 r = rospkg.RosPack() 37 pkg_dir = r.get_path(package) 38 results_log_name = rostest_name_from_path(pkg_dir, filename) 39 log_basename = 'rocon_test-%s-%s.log' % (socket.gethostname(), os.getpid()) 40 unused_log_name = rosgraph.roslogging.configure_logging('rocon_test', filename=log_basename) 41 results_file = rosunit.xml_results_file(package, results_log_name, is_rostest=True) 42 return results_log_name, results_file
43 44
45 -def printlog(msg, *args):
46 if args: 47 msg = msg % args 48 logging.getLogger('rocon_test').info(msg) 49 print("[ROCON_TEST] " + msg)
50 51
52 -def printlogerr(msg, *args):
53 if args: 54 msg = msg % args 55 logging.getLogger('rocon_test').error(msg) 56 print >> sys.stderr, "[ROCON_TEST] " + msg
57 58 ############################################################################## 59 # Test 60 ############################################################################## 61 62 if __name__ == '__main__': 63 printlog(" Where is it dude?") 64