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

Use logging Formatter, enabling printing exception info with exc_info=1 #828

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 4 additions & 2 deletions tools/rosgraph/src/rosgraph/roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def makedirs_with_parent_perms(p):
'CRITICAL': ('FATAL', '\033[31m')
}
_color_reset = '\033[0m'
_defaultFormatter = logging.Formatter()

class RosStreamHandler(logging.Handler):
def __init__(self, colorize=True):
Expand All @@ -172,10 +173,11 @@ def __init__(self, colorize=True):

def emit(self, record):
level, color = _logging_to_rospy_names[record.levelname]
record_message = _defaultFormatter.format(record)
if 'ROSCONSOLE_FORMAT' in os.environ.keys():
msg = os.environ['ROSCONSOLE_FORMAT']
msg = msg.replace('${severity}', level)
msg = msg.replace('${message}', str(record.getMessage()))
msg = msg.replace('${message}', str(record_message))
msg = msg.replace('${walltime}', '%f' % time.time())
msg = msg.replace('${thread}', str(record.thread))
msg = msg.replace('${logger}', str(record.name))
Expand All @@ -198,7 +200,7 @@ def emit(self, record):
msg = '[%s] [WallTime: %f]' % (level, time.time())
if self._get_time is not None and not self._is_wallclock():
msg += ' [%f]' % self._get_time()
msg += ' %s\n' % record.getMessage()
msg += ' %s\n' % record_message
if record.levelno < logging.WARNING:
self._write(sys.stdout, msg, color)
else:
Expand Down