Skip to content

Commit

Permalink
Add timestamp formatting for rosconsole
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzozowski committed Dec 20, 2018
1 parent eb7e686 commit 3dec6fc
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tools/rosgraph/src/rosgraph/roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import logging
import logging.config
import inspect
import datetime

import yaml

Expand Down Expand Up @@ -241,7 +242,15 @@ def emit(self, record):
'ROSCONSOLE_FORMAT', '[${severity}] [${time}]: ${message}')
msg = msg.replace('${severity}', level)
msg = msg.replace('${message}', str(record_message))
msg = msg.replace('${walltime}', '%f' % time.time())

# walltime tag
msg = msg.replace('${walltime}', '%f' % time.time()) # for performance reasons

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

msg = msg.replace('${thread}', str(record.thread))
msg = msg.replace('${logger}', str(record.name))
msg = msg.replace('${file}', str(record.pathname))
Expand All @@ -253,10 +262,22 @@ def emit(self, record):
except ImportError:
node_name = '<unknown_node_name>'
msg = msg.replace('${node}', node_name)

# time tag
time_str = '%f' % time.time()
if self._get_time is not None and not self._is_wallclock():
time_str += ', %f' % self._get_time()
msg = msg.replace('${time}', time_str)
msg = msg.replace('${time}', time_str) # for performance reasons

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

if self._get_time is not None and not self._is_wallclock():
time_str += ', %f' % self._get_time()

msg = msg.replace('${time:' + time_format + '}', time_str)

msg += '\n'
if record.levelno < logging.WARNING:
self._write(self._stdout, msg, color)
Expand Down

0 comments on commit 3dec6fc

Please sign in to comment.