From 3dec6fc068fdc492fbd88a207e492614d58653dc Mon Sep 17 00:00:00 2001 From: abrzozowski Date: Thu, 20 Dec 2018 18:02:07 +0100 Subject: [PATCH] Add timestamp formatting for rosconsole --- tools/rosgraph/src/rosgraph/roslogging.py | 25 +++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/rosgraph/src/rosgraph/roslogging.py b/tools/rosgraph/src/rosgraph/roslogging.py index 4986e81cbe..b91d5f59f1 100644 --- a/tools/rosgraph/src/rosgraph/roslogging.py +++ b/tools/rosgraph/src/rosgraph/roslogging.py @@ -40,6 +40,7 @@ import logging import logging.config import inspect +import datetime import yaml @@ -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)) @@ -253,10 +262,22 @@ def emit(self, record): except ImportError: 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)