Skip to content

Commit

Permalink
Fixups during PR
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzozowski committed Feb 20, 2020
1 parent 5a626cf commit 27783bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/rosgraph/src/rosgraph/roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ def emit(self, record):
msg = msg.replace('${walltime}', '%f' % time.time()) # for performance reasons

while '${walltime:' in msg:
time_format = msg[msg.index('${walltime:') + len('${walltime:'): msg.index('}')]
tag_end_index = msg.index('${walltime:') + len('${walltime:')
time_format = msg[tag_end_index: msg.index('}', tag_end_index)]
time_str = time.strftime(time_format)
msg = msg.replace('${walltime:' + time_format + '}', time_str)

Expand All @@ -276,7 +277,8 @@ def emit(self, record):
msg = msg.replace('${time}', time_str) # for performance reasons

while '${time:' in msg:
time_format = msg[msg.index('${time:') + len('${time:'): msg.index('}')]
tag_end_index = msg.index('${time:') + len('${time:')
time_format = msg[tag_end_index: msg.index('}', tag_end_index)]
time_str = time.strftime(time_format)

if self._get_time is not None and not self._is_wallclock():
Expand Down
4 changes: 4 additions & 0 deletions tools/rosgraph/test/test_roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
'${severity}',
'${message}',
'${walltime}',
'${walltime:%Y-%m-%d %H:%M:%S}',
'${thread}',
'${logger}',
'${file}',
'${line}',
'${function}',
'${node}',
'${time}',
'${time:%Y-%m-%d %H:%M:%S}',
])
rosgraph.roslogging.configure_logging('test_rosgraph', logging.INFO)
loginfo = logging.getLogger('rosout').info
Expand Down Expand Up @@ -111,6 +113,7 @@ def test_rosconsole__logging_format():
'INFO',
'on ' + loc,
r'[0-9]*\.[0-9]*',
r'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}',
'[0-9]*',
'rosout',
re.escape(this_file),
Expand All @@ -119,6 +122,7 @@ def test_rosconsole__logging_format():
# depending if rospy.get_name() is available
'(/unnamed|<unknown_node_name>)',
r'[0-9]*\.[0-9]*',
r'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}',
])
assert_regexp_matches(lout.getvalue().splitlines()[i], log_out)

Expand Down
4 changes: 4 additions & 0 deletions tools/rosgraph/test/test_roslogging_user_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ def test_roslogging_user_logger():
'${severity}',
'${message}',
'${walltime}',
'${walltime:%Y-%m-%d %H:%M:%S}',
'${thread}',
'${logger}',
'${file}',
'${line}',
'${function}',
'${node}',
'${time}',
'${time:%Y-%m-%d %H:%M:%S}',
])
rosgraph.roslogging.configure_logging('test_rosgraph', logging.INFO)
loginfo = logging.getLogger('rosout.custom_logger_test').info
Expand Down Expand Up @@ -128,6 +130,7 @@ def test_roslogging_user_logger():
os.environ['ROS_IP'],
msg,
r'[0-9]*\.[0-9]*',
r'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}',
'[0-9]*',
'rosout.custom_logger_test',
'<filename>',
Expand All @@ -136,6 +139,7 @@ def test_roslogging_user_logger():
# depending if rospy.get_name() is available
'(/unnamed|<unknown_node_name>)',
r'[0-9]*\.[0-9]*',
r'[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}',
])
assert_regexp_matches(lout.getvalue().strip(), log_expected)

Expand Down

0 comments on commit 27783bc

Please sign in to comment.