Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding test changes, resolving merge conflicts #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/rospy/src/rospy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
get_node_uri, get_ros_root, \
logdebug, logwarn, loginfo, logout, logerr, logfatal, \
logdebug_throttle, logwarn_throttle, loginfo_throttle, logerr_throttle, logfatal_throttle, \
logdebug_throttle_identical, logwarn_throttle_identical, loginfo_throttle_identical, logerr_throttle_identical, logfatal_throttle_identical, \
logdebug_once, logwarn_once, loginfo_once, logerr_once, logfatal_once, \
parse_rosrpc_uri
from .exceptions import *
Expand Down
308 changes: 165 additions & 143 deletions clients/rospy/src/rospy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,105 +144,6 @@ def rospyerr(msg, *args):
def rospywarn(msg, *args):
"""Internal rospy client library warn logging"""
_rospy_logger.warn(msg, *args)


def _base_logger(msg, *args, **kwargs):

name = kwargs.pop('logger_name', None)
throttle = kwargs.pop('logger_throttle', None)
level = kwargs.pop('logger_level', None)
once = kwargs.pop('logger_once', False)
throttle_identical = kwargs.pop('logger_throttle_identical', False)

rospy_logger = logging.getLogger('rosout')
if name:
rospy_logger = rospy_logger.getChild(name)
logfunc = getattr(rospy_logger, level)

if once:
caller_id = _frame_to_caller_id(inspect.currentframe().f_back.f_back)
if _logging_once(caller_id):
logfunc(msg, *args)
elif throttle_identical:
caller_id = _frame_to_caller_id(inspect.currentframe().f_back.f_back)
throttle_elapsed = False
if throttle is not None:
throttle_elapsed = _logging_throttle(caller_id, throttle)
if _logging_identical(caller_id, msg) or throttle_elapsed:
logfunc(msg, *args)
elif throttle:
caller_id = _frame_to_caller_id(inspect.currentframe().f_back.f_back)
if _logging_throttle(caller_id, throttle):
logfunc(msg, *args)
else:
logfunc(msg, *args)


def logdebug(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='debug', **kwargs)

def loginfo(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='info', **kwargs)

def logwarn(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='warn', **kwargs)

def logerr(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='error', **kwargs)

def logfatal(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='critical', **kwargs)

logout = loginfo # alias deprecated name

logerror = logerr # alias logerr


class LoggingThrottle(object):

last_logging_time_table = {}

def __call__(self, caller_id, period):
"""Do logging specified message periodically.

- 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(caller_id)

if (last_logging_time is None or
(now - last_logging_time) > rospy.Duration(period)):
self.last_logging_time_table[caller_id] = now
return True
return False


_logging_throttle = LoggingThrottle()


class LoggingIdentical(object):

last_logging_msg_table = {}

def __call__(self, caller_id, msg):
"""Do logging specified message only if distinct from last message.

- caller_id (str): Id to identify the caller
- msg (str): Contents of message to log
"""
msg_hash = md5(msg).hexdigest()

if msg_hash != self.last_logging_msg_table.get(caller_id):
self.last_logging_msg_table[caller_id] = msg_hash
return True
return False


_logging_identical = LoggingIdentical()


def _frame_to_caller_id(frame):
Expand All @@ -253,50 +154,171 @@ def _frame_to_caller_id(frame):
)
return pickle.dumps(caller_id)


def logdebug_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='debug')

def loginfo_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='info')

def logwarn_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='warn')

def logerr_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='error')

def logfatal_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='critical')

class LoggingOnce(object):

called_caller_ids = set()

def __call__(self, caller_id):
if caller_id not in self.called_caller_ids:
self.called_caller_ids.add(caller_id)
return True
return False

_logging_once = LoggingOnce()


def logdebug_once(msg):
_base_logger(msg, logger_once=True, logger_level='debug')

def loginfo_once(msg):
_base_logger(msg, logger_once=True, logger_level='info')

def logwarn_once(msg):
_base_logger(msg, logger_once=True, logger_level='warn')

def logerr_once(msg):
_base_logger(msg, logger_once=True, logger_level='error')

def logfatal_once(msg):
_base_logger(msg, logger_once=True, logger_level='critical')


def _base_logger(msg, *args, **kwargs):

name = kwargs.pop('logger_name', None)
throttle = kwargs.pop('logger_throttle', None)
level = kwargs.pop('logger_level', None)
once = kwargs.pop('logger_once', False)
throttle_identical = kwargs.pop('logger_throttle_identical', False)

rospy_logger = logging.getLogger('rosout')
if name:
rospy_logger = rospy_logger.getChild(name)
logfunc = getattr(rospy_logger, level)

if once:
caller_id = _frame_to_caller_id(inspect.currentframe().f_back.f_back)
if _logging_once(caller_id):
logfunc(msg, *args)
elif throttle_identical:
caller_id = _frame_to_caller_id(inspect.currentframe().f_back.f_back)
throttle_elapsed = False
if throttle is not None:
throttle_elapsed = _logging_throttle(caller_id, throttle)
if _logging_identical(caller_id, msg) or throttle_elapsed:
logfunc(msg, *args)
elif throttle:
caller_id = _frame_to_caller_id(inspect.currentframe().f_back.f_back)
if _logging_throttle(caller_id, throttle):
logfunc(msg, *args)
else:
logfunc(msg, *args)


def logdebug(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='debug', **kwargs)

def loginfo(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='info', **kwargs)

def logwarn(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='warn', **kwargs)

def logerr(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='error', **kwargs)

def logfatal(msg, *args, **kwargs):
_base_logger(msg, *args, logger_level='critical', **kwargs)

logout = loginfo # alias deprecated name

logerror = logerr # alias logerr


class LoggingThrottle(object):

last_logging_time_table = {}

def __call__(self, caller_id, period):
"""Do logging specified message periodically.

- 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(caller_id)

if (last_logging_time is None or
(now - last_logging_time) > rospy.Duration(period)):
self.last_logging_time_table[caller_id] = now
return True
return False


_logging_throttle = LoggingThrottle()


def logdebug_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='debug')

def loginfo_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='info')

def logwarn_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='warn')

def logerr_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='error')

def logfatal_throttle(period, msg):
_base_logger(msg, logger_throttle=period, logger_level='critical')


class LoggingIdentical(object):

last_logging_msg_table = {}

def __call__(self, caller_id, msg):
"""Do logging specified message only if distinct from last message.

- caller_id (str): Id to identify the caller
- msg (str): Contents of message to log
"""
msg_hash = md5(msg).hexdigest()

if msg_hash != self.last_logging_msg_table.get(caller_id):
self.last_logging_msg_table[caller_id] = msg_hash
return True
return False


_logging_identical = LoggingIdentical()


def logdebug_throttle_identical(period, msg):
_base_logger(msg, logger_throttle=period, logger_throttle_identical=True,
logger_level='debug')

def loginfo_throttle_identical(period, msg):
_base_logger(msg, logger_throttle=period, logger_throttle_identical=True,
logger_level='info')

def logwarn_throttle_identical(period, msg):
_base_logger(msg, logger_throttle=period, logger_throttle_identical=True,
logger_level='warn')

def logerr_throttle_identical(period, msg):
_base_logger(msg, logger_throttle=period, logger_throttle_identical=True,
logger_level='error')

def logfatal_throttle_identical(period, msg):
_base_logger(msg, logger_throttle=period, logger_throttle_identical=True,
logger_level='critical')


class LoggingOnce(object):

called_caller_ids = set()

def __call__(self, caller_id):
if caller_id not in self.called_caller_ids:
self.called_caller_ids.add(caller_id)
return True
return False

_logging_once = LoggingOnce()


def logdebug_once(msg):
_base_logger(msg, logger_once=True, logger_level='debug')

def loginfo_once(msg):
_base_logger(msg, logger_once=True, logger_level='info')

def logwarn_once(msg):
_base_logger(msg, logger_once=True, logger_level='warn')

def logerr_once(msg):
_base_logger(msg, logger_once=True, logger_level='error')

def logfatal_once(msg):
_base_logger(msg, logger_once=True, logger_level='critical')


#########################################################
# CONSTANTS
Expand Down
Loading