summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Salmon <will.salmon@codethink.co.uk>2019-02-07 10:58:54 +0000
committerWill Salmon <will.salmon@codethink.co.uk>2019-02-07 10:58:54 +0000
commite61f471376d6d3ef2691abf3eee75d30999e7f05 (patch)
treef204d6422d6a04816e14aa988b9ebcd42c01cd0f
parent1a75b252ba4b91ab4d3c84cb5081d1039d1c3f0f (diff)
parent7285e87ec56aad9e88f90e7d8c4524e5cf477bdf (diff)
downloadbuildstream-e61f471376d6d3ef2691abf3eee75d30999e7f05.tar.gz
Merge branch 'willsalmon/log_formating' into 'master'
Add more log formatting options See merge request BuildStream/buildstream!1125
-rw-r--r--buildstream/_frontend/widget.py17
-rw-r--r--tests/frontend/logging.py6
2 files changed, 19 insertions, 4 deletions
diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py
index c5353bc43..de122f8a3 100644
--- a/buildstream/_frontend/widget.py
+++ b/buildstream/_frontend/widget.py
@@ -94,12 +94,24 @@ class FixedText(Widget):
# Used to add the wallclock time this message was created at
class WallclockTime(Widget):
+ def __init__(self, context, content_profile, format_profile, output_format=False):
+ self._output_format = output_format
+ super(WallclockTime, self).__init__(context, content_profile, format_profile)
+
def render(self, message):
+
fields = [self.content_profile.fmt("{:02d}".format(x)) for x in
[message.creation_time.hour,
message.creation_time.minute,
- message.creation_time.second]]
- return self.format_profile.fmt(":").join(fields)
+ message.creation_time.second,
+ ]
+ ]
+ text = self.format_profile.fmt(":").join(fields)
+
+ if self._output_format == 'us':
+ text += self.content_profile.fmt(".{:06d}".format(message.creation_time.microsecond))
+
+ return text
# A widget for rendering the debugging column
@@ -326,6 +338,7 @@ class LogLine(Widget):
"elapsed": TimeCode(context, content_profile, format_profile, microseconds=False),
"elapsed-us": TimeCode(context, content_profile, format_profile, microseconds=True),
"wallclock": WallclockTime(context, content_profile, format_profile),
+ "wallclock-us": WallclockTime(context, content_profile, format_profile, output_format='us'),
"key": CacheKey(context, content_profile, format_profile, err_profile),
"element": ElementName(context, content_profile, format_profile),
"action": TypeName(context, content_profile, format_profile),
diff --git a/tests/frontend/logging.py b/tests/frontend/logging.py
index 3243e74bc..ddaadfa26 100644
--- a/tests/frontend/logging.py
+++ b/tests/frontend/logging.py
@@ -52,7 +52,8 @@ def test_custom_logging(cli, tmpdir, datafiles):
element_path = os.path.join(project, 'elements')
element_name = 'fetch-test-git.bst'
- custom_log_format = '%{elapsed},%{elapsed-us},%{wallclock},%{key},%{element},%{action},%{message}'
+ custom_log_format = ('%{elapsed},%{elapsed-us},%{wallclock},%{wallclock-us},'
+ '%{key},%{element},%{action},%{message}')
user_config = {'logging': {'message-format': custom_log_format}}
cli.configure(user_config)
@@ -77,7 +78,8 @@ def test_custom_logging(cli, tmpdir, datafiles):
result = cli.run(project=project, args=['source', 'fetch', element_name])
result.assert_success()
- m = re.search(r"\d\d:\d\d:\d\d,\d\d:\d\d:\d\d.\d{6},\d\d:\d\d:\d\d,\s*,.*,SUCCESS,Checking sources", result.stderr)
+ m = re.search(r"\d\d:\d\d:\d\d,\d\d:\d\d:\d\d.\d{6},\d\d:\d\d:\d\d,\d\d:\d\d:\d\d.\d{6}\s*,.*"
+ r",SUCCESS,Checking sources", result.stderr)
assert(m is not None)