Skip to content

Commit

Permalink
Get column number to get correct caller id
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Jun 3, 2016
1 parent 0ce4f9e commit 98e3a64
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions clients/rospy/src/rospy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,50 +160,60 @@ class LoggingThrottle(object):

last_logging_time_table = {}

def __call__(self, id, logging_func, period, msg):
def __call__(self, caller_id, logging_func, period, msg):
"""Do logging specified message periodically.
- id (str): Id to identify the caller
- caller_id (str): Id to identify the caller
- logging_func (function): Function to do logging.
- period (float): Period to do logging in second unit.
- msg (object): Message to do logging.
"""
now = rospy.Time.now()

last_logging_time = self.last_logging_time_table.get(id)
last_logging_time = self.last_logging_time_table.get(caller_id)

if (last_logging_time is None or
(now - last_logging_time) > rospy.Duration(period)):
logging_func(msg)
self.last_logging_time_table[id] = now
self.last_logging_time_table[caller_id] = now


_logging_throttle = LoggingThrottle()


def _frame_record_to_caller_id(frame_record):
frame, _, lineno, _, code, _ = frame_record
caller_id = (
inspect.getabsfile(frame),
lineno,
frame.f_lasti,
)
return pickle.dumps(caller_id)


def logdebug_throttle(period, msg):
id_ = pickle.dumps(inspect.stack()[1][1:])
_logging_throttle(id_, logdebug, period, msg)
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logdebug, period, msg)


def loginfo_throttle(period, msg):
id_ = pickle.dumps(inspect.stack()[1][1:])
_logging_throttle(id_, loginfo, period, msg)
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, loginfo, period, msg)


def logwarn_throttle(period, msg):
id_ = pickle.dumps(inspect.stack()[1][1:])
_logging_throttle(id_, logwarn, period, msg)
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logwarn, period, msg)


def logerr_throttle(period, msg):
id_ = pickle.dumps(inspect.stack()[1][1:])
_logging_throttle(id_, logerr, period, msg)
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logerr, period, msg)


def logfatal_throttle(period, msg):
id_ = pickle.dumps(inspect.stack()[1][1:])
_logging_throttle(id_, logfatal, period, msg)
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logfatal, period, msg)


#########################################################
Expand Down

0 comments on commit 98e3a64

Please sign in to comment.