Skip to content

Commit

Permalink
Fixed ROSCONSOLE_FORMAT with microseconds (#2370)
Browse files Browse the repository at this point in the history
  • Loading branch information
peci1 authored Sep 4, 2024
1 parent b1ef2ee commit aef16f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools/rosgraph/src/rosgraph/roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def emit(self, record):
while '${walltime:' in msg:
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)
time_str = datetime.datetime.now().strftime(time_format)
msg = msg.replace('${walltime:' + time_format + '}', time_str)

msg = msg.replace('${thread}', str(record.thread))
Expand All @@ -279,7 +279,7 @@ def emit(self, record):
while '${time:' in msg:
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)
time_str = datetime.datetime.now().strftime(time_format)

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

Expand Down

0 comments on commit aef16f0

Please sign in to comment.