Will Salmon pushed to branch willsalmon/log_formating at BuildStream / buildstream
Commits:
- 
cb0618d2
by William Salmon at 2019-02-06T13:25:31Z
2 changed files:
Changes:
| ... | ... | @@ -94,12 +94,24 @@ class FixedText(Widget): | 
| 94 | 94 |  | 
| 95 | 95 |  # Used to add the wallclock time this message was created at
 | 
| 96 | 96 |  class WallclockTime(Widget):
 | 
| 97 | +    def __init__(self, context, content_profile, format_profile, output_format=False):
 | |
| 98 | +        self._output_format = output_format
 | |
| 99 | +        super(WallclockTime, self).__init__(context, content_profile, format_profile)
 | |
| 100 | + | |
| 97 | 101 |      def render(self, message):
 | 
| 102 | + | |
| 98 | 103 |          fields = [self.content_profile.fmt("{:02d}".format(x)) for x in
 | 
| 99 | 104 |                    [message.creation_time.hour,
 | 
| 100 | 105 |                     message.creation_time.minute,
 | 
| 101 | -                   message.creation_time.second]]
 | |
| 102 | -        return self.format_profile.fmt(":").join(fields)
 | |
| 106 | +                   message.creation_time.second,
 | |
| 107 | +                   ]
 | |
| 108 | +                  ]
 | |
| 109 | +        text = self.format_profile.fmt(":").join(fields)
 | |
| 110 | + | |
| 111 | +        if self._output_format == 'us':
 | |
| 112 | +            text += self.format_profile.fmt(".{:06d}".format(message.creation_time.microsecond))
 | |
| 113 | + | |
| 114 | +        return text
 | |
| 103 | 115 |  | 
| 104 | 116 |  | 
| 105 | 117 |  # A widget for rendering the debugging column
 | 
| ... | ... | @@ -326,6 +338,7 @@ class LogLine(Widget): | 
| 326 | 338 |              "elapsed": TimeCode(context, content_profile, format_profile, microseconds=False),
 | 
| 327 | 339 |              "elapsed-us": TimeCode(context, content_profile, format_profile, microseconds=True),
 | 
| 328 | 340 |              "wallclock": WallclockTime(context, content_profile, format_profile),
 | 
| 341 | +            "wallclock-us": WallclockTime(context, content_profile, format_profile, output_format='us'),
 | |
| 329 | 342 |              "key": CacheKey(context, content_profile, format_profile, err_profile),
 | 
| 330 | 343 |              "element": ElementName(context, content_profile, format_profile),
 | 
| 331 | 344 |              "action": TypeName(context, content_profile, format_profile),
 | 
| ... | ... | @@ -52,7 +52,8 @@ def test_custom_logging(cli, tmpdir, datafiles): | 
| 52 | 52 |      element_path = os.path.join(project, 'elements')
 | 
| 53 | 53 |      element_name = 'fetch-test-git.bst'
 | 
| 54 | 54 |  | 
| 55 | -    custom_log_format = '%{elapsed},%{elapsed-us},%{wallclock},%{key},%{element},%{action},%{message}'
 | |
| 55 | +    custom_log_format = ('%{elapsed},%{elapsed-us},%{wallclock},%{wallclock-us},'
 | |
| 56 | +                         '%{key},%{element},%{action},%{message}')
 | |
| 56 | 57 |      user_config = {'logging': {'message-format': custom_log_format}}
 | 
| 57 | 58 |      cli.configure(user_config)
 | 
| 58 | 59 |  | 
| ... | ... | @@ -77,7 +78,8 @@ def test_custom_logging(cli, tmpdir, datafiles): | 
| 77 | 78 |      result = cli.run(project=project, args=['source', 'fetch', element_name])
 | 
| 78 | 79 |      result.assert_success()
 | 
| 79 | 80 |  | 
| 80 | -    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)
 | |
| 81 | +    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*,.*"
 | |
| 82 | +                  r",SUCCESS,Checking sources", result.stderr)
 | |
| 81 | 83 |      assert(m is not None)
 | 
| 82 | 84 |  | 
| 83 | 85 |  | 
