Changeset c914e1d in rtems-source-builder for source-builder/sb/log.py
- Timestamp:
- 05/01/13 00:08:36 (10 years ago)
- Branches:
- 4.10, 4.11, 4.9, 5, master
- Children:
- df56f7e
- Parents:
- 3c69de0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source-builder/sb/log.py
r3c69de0 rc914e1d 89 89 class log: 90 90 """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 92 94 self.fhs = [None, None] 93 95 if streams: … … 108 110 self.fhs[f].close() 109 111 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 110 125 def has_stdout(self): 111 126 return self.fhs[0] is not None … … 117 132 """Output the text message to all the logs.""" 118 133 # Reformat the text to have local line types. 134 text = text.replace(chr(13), '').splitlines() 135 self._tail(text) 119 136 out = '' 120 for l in text .replace(chr(13), '').splitlines():137 for l in text: 121 138 out += l + os.linesep 122 139 for f in range(0, len(self.fhs)): … … 132 149 133 150 if __name__ == "__main__": 134 l = log(['stdout', 'log.txt'] )151 l = log(['stdout', 'log.txt'], tail_size = 20) 135 152 for i in range(0, 10): 136 153 l.output('log: hello world: %d\n' % (i)) … … 138 155 l.output('log: hello world NONE') 139 156 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 140 168 for i in [0, 1]: 141 169 quiet = False … … 160 188 notice('notice with quiet on and trace on') 161 189 default = l 190 print '=-' * 40 191 print 'tail: %d' % (len(l.tail)) 192 print l 193 print '=-' * 40 162 194 del l
Note: See TracChangeset
for help on using the changeset viewer.