logger.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import rospy
3 
4 from flexbe_core.proxy import ProxyPublisher
5 from flexbe_msgs.msg import BehaviorLog
6 
7 
8 '''
9 Created on 12/17/2014
10 
11 @author: Philipp Schillinger
12 '''
13 class Logger(object):
14  '''
15  Realizes behavior-specific logging.
16  '''
17  REPORT_INFO = BehaviorLog.INFO
18  REPORT_WARN = BehaviorLog.WARN
19  REPORT_HINT = BehaviorLog.HINT
20  REPORT_ERROR = BehaviorLog.ERROR
21 
22  LOGGING_TOPIC = 'flexbe/log'
23 
24  _last_status_update = None
25  _pub = None
26 
27  @staticmethod
28  def initialize():
29  Logger._pub = ProxyPublisher({Logger.LOGGING_TOPIC: BehaviorLog})
30 
31  @staticmethod
32  def log(text, severity):
33  if Logger._last_status_update is not None:
34  elapsed = rospy.get_rostime() - Logger._last_status_update;
35  if (elapsed.to_sec() < 0.1):
36  rospy.sleep(0.05)
37  Logger._last_status_update = rospy.get_rostime()
38 
39  msg = BehaviorLog()
40  msg.text = str(text)
41  msg.status_code = severity
42  Logger._pub.publish(Logger.LOGGING_TOPIC, msg)
43 
44  if severity == Logger.REPORT_INFO:
45  rospy.loginfo(text)
46  elif severity == Logger.REPORT_WARN:
47  rospy.logwarn(text)
48  elif severity == Logger.REPORT_HINT:
49  rospy.loginfo('\033[94mBehavior Hint: %s\033[0m', text)
50  elif severity == Logger.REPORT_ERROR:
51  rospy.logerr(text)
52 
53 
54  @staticmethod
55  def loginfo(text):
56  Logger.log(text, Logger.REPORT_INFO)
57 
58  @staticmethod
59  def logwarn(text):
60  Logger.log(text, Logger.REPORT_WARN)
61 
62  @staticmethod
63  def loghint(text):
64  Logger.log(text, Logger.REPORT_HINT)
65 
66  @staticmethod
67  def logerr(text):
68  Logger.log(text, Logger.REPORT_ERROR)
def log(text, severity)
Definition: logger.py:32


flexbe_core
Author(s): Philipp Schillinger
autogenerated on Wed Jun 5 2019 21:51:59