logger.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 
4 from flexbe_msgs.msg import BehaviorLog
5 
6 
7 class Logger(object):
8  '''
9  Realizes behavior-specific logging.
10  '''
11  REPORT_INFO = BehaviorLog.INFO
12  REPORT_WARN = BehaviorLog.WARN
13  REPORT_HINT = BehaviorLog.HINT
14  REPORT_ERROR = BehaviorLog.ERROR
15  REPORT_DEBUG = BehaviorLog.DEBUG
16 
17  LOGGING_TOPIC = 'flexbe/log'
18 
19  _pub = None
20 
21  @staticmethod
22  def initialize():
23  Logger._pub = rospy.Publisher(Logger.LOGGING_TOPIC, BehaviorLog, queue_size=100)
24 
25  @staticmethod
26  def log(text, severity):
27  if Logger._pub is None:
28  Logger.initialize()
29  # send message with logged text
30  msg = BehaviorLog()
31  msg.text = str(text)
32  msg.status_code = severity
33  Logger._pub.publish(msg)
34  # also log locally
35  Logger.local(text, severity)
36 
37  @staticmethod
38  def local(text, severity):
39  if severity == Logger.REPORT_INFO:
40  rospy.loginfo(text)
41  elif severity == Logger.REPORT_WARN:
42  rospy.logwarn(text)
43  elif severity == Logger.REPORT_HINT:
44  rospy.loginfo('\033[94mBehavior Hint: %s\033[0m', text)
45  elif severity == Logger.REPORT_ERROR:
46  rospy.logerr(text)
47  elif severity == Logger.REPORT_DEBUG:
48  rospy.logdebug(text)
49  else:
50  rospy.logdebug(text + ' (unknown log level %s)' % str(severity))
51 
52  @staticmethod
53  def logdebug(text, *args):
54  Logger.log(text % args, Logger.REPORT_DEBUG)
55 
56  @staticmethod
57  def loginfo(text, *args):
58  Logger.log(text % args, Logger.REPORT_INFO)
59 
60  @staticmethod
61  def logwarn(text, *args):
62  Logger.log(text % args, Logger.REPORT_WARN)
63 
64  @staticmethod
65  def loghint(text, *args):
66  Logger.log(text % args, Logger.REPORT_HINT)
67 
68  @staticmethod
69  def logerr(text, *args):
70  Logger.log(text % args, Logger.REPORT_ERROR)
71 
72  @staticmethod
73  def localdebug(text, *args):
74  Logger.local(text % args, Logger.REPORT_DEBUG)
75 
76  @staticmethod
77  def localinfo(text, *args):
78  Logger.local(text % args, Logger.REPORT_INFO)
def localdebug(text, args)
Definition: logger.py:73
def loghint(text, args)
Definition: logger.py:65
def local(text, severity)
Definition: logger.py:38
def log(text, severity)
Definition: logger.py:26
def localinfo(text, args)
Definition: logger.py:77
def logerr(text, args)
Definition: logger.py:69
def loginfo(text, args)
Definition: logger.py:57
def logwarn(text, args)
Definition: logger.py:61
def logdebug(text, args)
Definition: logger.py:53


flexbe_core
Author(s): Philipp Schillinger
autogenerated on Sun Dec 13 2020 04:01:39