[Notes] [Git][BuildStream/buildstream][willsalmon/log_formating] Add more log formatting options



Title: GitLab

Will Salmon pushed to branch willsalmon/log_formating at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/_frontend/widget.py
    ... ... @@ -8,7 +8,7 @@
    8 8
     #
    
    9 9
     #  This library is distributed in the hope that it will be useful,
    
    10 10
     #  but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    11
    -#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
    
    11
    +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    
    12 12
     #  Lesser General Public License for more details.
    
    13 13
     #
    
    14 14
     #  You should have received a copy of the GNU Lesser General Public
    
    ... ... @@ -17,6 +17,7 @@
    17 17
     #  Authors:
    
    18 18
     #        Tristan Van Berkom <tristan vanberkom codethink co uk>
    
    19 19
     import datetime
    
    20
    +import base64
    
    20 21
     import os
    
    21 22
     from collections import defaultdict, OrderedDict
    
    22 23
     from contextlib import ExitStack
    
    ... ... @@ -94,12 +95,24 @@ class FixedText(Widget):
    94 95
     
    
    95 96
     # Used to add the wallclock time this message was created at
    
    96 97
     class WallclockTime(Widget):
    
    98
    +    def __init__(self, context, content_profile, format_profile, output_format=False):
    
    99
    +        self._output_format = output_format
    
    100
    +        super(WallclockTime, self).__init__(context, content_profile, format_profile)
    
    101
    +
    
    97 102
         def render(self, message):
    
    103
    +
    
    98 104
             fields = [self.content_profile.fmt("{:02d}".format(x)) for x in
    
    99 105
                       [message.creation_time.hour,
    
    100 106
                        message.creation_time.minute,
    
    101
    -                   message.creation_time.second]]
    
    102
    -        return self.format_profile.fmt(":").join(fields)
    
    107
    +                   message.creation_time.second,
    
    108
    +                   ]
    
    109
    +                  ]
    
    110
    +        text = self.format_profile.fmt(":").join(fields)
    
    111
    +
    
    112
    +        if self._output_format == 'us':
    
    113
    +            text += self.format_profile.fmt(".{:06d}".format(message.creation_time.microsecond))
    
    114
    +
    
    115
    +        return text
    
    103 116
     
    
    104 117
     
    
    105 118
     # A widget for rendering the debugging column
    
    ... ... @@ -326,6 +339,8 @@ class LogLine(Widget):
    326 339
                 "elapsed": TimeCode(context, content_profile, format_profile, microseconds=False),
    
    327 340
                 "elapsed-us": TimeCode(context, content_profile, format_profile, microseconds=True),
    
    328 341
                 "wallclock": WallclockTime(context, content_profile, format_profile),
    
    342
    +            "wallclock-us": WallclockTime(context, content_profile, format_profile, output_format='us'),
    
    343
    +            "wallclock-base64": WallclockTime(context, content_profile, format_profile, output_format='base64'),
    
    329 344
                 "key": CacheKey(context, content_profile, format_profile, err_profile),
    
    330 345
                 "element": ElementName(context, content_profile, format_profile),
    
    331 346
                 "action": TypeName(context, content_profile, format_profile),
    

  • tests/frontend/logging.py
    ... ... @@ -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
     
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]