Changeset c914e1d in rtems-source-builder for source-builder/sb/log.py


Ignore:
Timestamp:
05/01/13 00:08:36 (10 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, 4.9, 5, master
Children:
df56f7e
Parents:
3c69de0
Message:

Add tail support to the log. Email the log tail in a failure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source-builder/sb/log.py

    r3c69de0 rc914e1d  
    8989class log:
    9090    """Log output to stdout or a file."""
    91     def __init__(self, streams = None):
     91    def __init__(self, streams = None, tail_size = 100):
     92        self.tail = []
     93        self.tail_size = tail_size
    9294        self.fhs = [None, None]
    9395        if streams:
     
    108110            self.fhs[f].close()
    109111
     112    def __str__(self):
     113        t = ''
     114        for tl in self.tail:
     115            t += tl + os.linesep
     116        return t[:-len(os.linesep)]
     117
     118    def _tail(self, text):
     119        if type(text) is not list:
     120            text = text.splitlines()
     121        self.tail += text
     122        if len(self.tail) > self.tail_size:
     123            self.tail = self.tail[-self.tail_size:]
     124
    110125    def has_stdout(self):
    111126        return self.fhs[0] is not None
     
    117132        """Output the text message to all the logs."""
    118133        # Reformat the text to have local line types.
     134        text = text.replace(chr(13), '').splitlines()
     135        self._tail(text)
    119136        out = ''
    120         for l in text.replace(chr(13), '').splitlines():
     137        for l in text:
    121138            out += l + os.linesep
    122139        for f in range(0, len(self.fhs)):
     
    132149
    133150if __name__ == "__main__":
    134     l = log(['stdout', 'log.txt'])
     151    l = log(['stdout', 'log.txt'], tail_size = 20)
    135152    for i in range(0, 10):
    136153        l.output('log: hello world: %d\n' % (i))
     
    138155    l.output('log: hello world NONE')
    139156    l.flush()
     157    print '=-' * 40
     158    print 'tail: %d' % (len(l.tail))
     159    print l
     160    print '=-' * 40
     161    for i in range(0, 10):
     162        l.output('log: hello world 2: %d\n' % (i))
     163    l.flush()
     164    print '=-' * 40
     165    print 'tail: %d' % (len(l.tail))
     166    print l
     167    print '=-' * 40
    140168    for i in [0, 1]:
    141169        quiet = False
     
    160188        notice('notice with quiet on and trace on')
    161189        default = l
     190    print '=-' * 40
     191    print 'tail: %d' % (len(l.tail))
     192    print l
     193    print '=-' * 40
    162194    del l
Note: See TracChangeset for help on using the changeset viewer.