loggers.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # License: BSD
4 # https://raw.github.com/robotics-in-concert/rocon_multimaster/license/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 def xml_results_file(package, results_log_name):
29  '''
30  Generate the absolute results log file name. This will be located in the
31  cmake build directory, prefixed with 'rocon_test' and using the specially
32  generated underscore separated log name.
33  '''
34  results_log_file = rosunit.xml_results_file(package, results_log_name, is_rostest=True)
35  # rostest's results_file is prefixed with 'rostest' - switch it to our 'rocon_test'
36  return results_log_file.replace('rostest', 'rocon_test', 1)
37 
38 def configure_logging(package, filename):
39  '''
40  Configures the logger and generates an underscored pkg_dir relative name
41  (e.g. launch/pirate_chatter.multilaunch -> launch_pirate_chatter
42  '''
43  roslaunch.core.add_printlog_handler(logging.getLogger('rocon_test').info)
44  roslaunch.core.add_printerrlog_handler(logging.getLogger('rocon_test').error)
45  r = rospkg.RosPack()
46  pkg_dir = r.get_path(package)
47  results_log_name = rostest_name_from_path(pkg_dir, filename)
48  log_basename = 'rocon_test-%s-%s.log' % (socket.gethostname(), os.getpid())
49  unused_log_name = rosgraph.roslogging.configure_logging('rocon_test', filename=log_basename)
50  results_log_file = xml_results_file(package, results_log_name)
51  return results_log_name, results_log_file
52 
53 
54 def printlog(msg, *args):
55  if args:
56  msg = msg % args
57  logging.getLogger('rocon_test').info(msg)
58  print("[ROCON_TEST] " + msg)
59 
60 
61 def printlogerr(msg, *args):
62  if args:
63  msg = msg % args
64  logging.getLogger('rocon_test').error(msg)
65  print >> sys.stderr, "[ROCON_TEST] " + msg
66 
67 ##############################################################################
68 # Test
69 ##############################################################################
70 
71 if __name__ == '__main__':
72  printlog(" Where is it dude?")
def configure_logging(package, filename)
Definition: loggers.py:38
def printlog(msg, args)
Definition: loggers.py:54
def printlogerr(msg, args)
Definition: loggers.py:61
def xml_results_file(package, results_log_name)
Methods.
Definition: loggers.py:28


rocon_test
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 14:40:14