From 485b8714f9fa29879442a4d070b397a98b6c03e8 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Thu, 10 Dec 2020 11:31:53 +0100 Subject: [PATCH] Fix formatting of lists of non-string objects when logging --- reframe/core/logging.py | 11 +++++++---- unittests/test_logging.py | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/reframe/core/logging.py b/reframe/core/logging.py index 68949bba09..8eb53d7889 100644 --- a/reframe/core/logging.py +++ b/reframe/core/logging.py @@ -166,14 +166,17 @@ def _format_time_rfc3339(timestamp, datefmt): def _xfmt(val): - if isinstance(val, str): - return val + def _dofmt(v): + if isinstance(v, str): + return v + else: + return jsonext.dumps(v) # NOTE: This is for compatibility with older formatting if isinstance(val, (list, tuple, set)): - return ','.join(val) + return ','.join(_dofmt(v) for v in val) - return jsonext.dumps(val) + return _dofmt(val) class CheckFieldFormatter(logging.Formatter): diff --git a/unittests/test_logging.py b/unittests/test_logging.py index a7cb591251..964d1fe924 100644 --- a/unittests/test_logging.py +++ b/unittests/test_logging.py @@ -41,7 +41,7 @@ def error(): 'fakejob') test.job._completion_time = time.time() test.custom = 'hello extras' - test.custom_list = ['custom', 'attr'] + test.custom_list = ['custom', 3.0, ['hello', 'world']] test.custom_dict = {'a': 1, 'b': 2} test.deferred = sn.defer('hello') test.deferred_error = error() @@ -163,7 +163,8 @@ def test_logger_dynamic_attributes(logfile, logger_with_check): logger_with_check.logger.handlers[0].setFormatter(formatter) logger_with_check.info('xxx') assert _pattern_in_logfile( - r'hello extras\|custom,attr\|null\|{"a": 1, "b": 2}', logfile + r'hello extras\|custom,3.0,\["hello", "world"\]\|null\|' + r'{"a": 1, "b": 2}', logfile )